Skip to main content

New Article

How to SUM by matching partial text in Excel

A String exercise in Excel VBA

For best understanding you need to practice with real data problem. From this point of view, I'm going to solve a String problem from real life experience.


Problem:

The problem is a raw data after downloading from data server, the SKU (Stock Keeping Unit) code wrongly encoded as "SKU-US-90/10/45". To make a SKU wise Stock Report you need to convert the SKU code to correct format like below image:

Image 1: RawData SKU and Corrected SKU


Solution:

The problems are:
  • Converting US to USA
  • "/" to ""
  • "-" to ""
Use the below code to convert all the wrong SKU to correct SKU:


Sub CorSKU()
   Dim x As String
   Dim i As Integer
   For i = 2 To 8
      x = Cells(i, 1).Value
      Cells(i, 3).Value = Replace(Replace(Replace(x, "US", "USA"), "/", ""), "-", "")
   Next i
End Sub


Here is the result:

Image 2: Result got from VBA


By this way practice with real data for better understanding.

|||| Please SUBSCRIBE our YouTube Channel ||||
https://www.youtube.com/channel/UCIWaA5KCwZzBGwtmGIOFjQw