Here is the code.
Private Sub RemoveSkuIndexes()
' *********************************************************************
' Removes all indexes leaving base Sku
' *********************************************************************
Dim LastRow As Integer
Dim Pos As Integer
Dim SKU As String
Dim TrimSKU as String
' Find lastrow in worksheet
LastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
' Cylce through each cell in column A until lastrow
For Each i In Range("A2:A" & LastRow)
SKU = i.Value
' Returns position of first hyphen from the left
Pos = InStr(1, SKU, "-", vbTextCompare)
' Returns string to the left of the hyphen
If Pos > 0 Then
TrimSKU = Left(Text, Pos - 1)
Else
TrimSKU = SKU
End If
' Overwrites cell content with truncated text
i.Value = TrimSKU
Next
End Sub
Bookmarks