removing prefix from part numbers

22strider

Active Member
Joined
Jun 11, 2007
Messages
311
Hello Firends

I have a huge column of data. This data has few prefixes that I need to remove. I have a list of possible prefixes. Some prefixes are 1,2,3 or 4 characters long. Could you please suggest best way of removing these prefixes (VBA if possible)?

Following are some of the examples of prefixes:
AB
GD
KR
BCD
FP-
TJ-
W

Thanks for your time
Rajesh
 
Hi!

Try this
VBA Function :)

Code:
Option Explicit

Function NoPrefixes(Text As String) As String

    Dim PreList As Variant
    Dim PreLen As Integer
    Dim TextLen As Integer
    Dim x As Byte
    
    Application.Volatile True

    PreList = Array("AB", "GD", "KR", "BCD", "FP-", "TJ-", "W") 'You must complete this list
    TextLen = Trim(Len(Text))
    NoPrefixes = Text

    For x = 0 To UBound(PreList)
        PreLen = Len(PreList(x))
            If InStr(1, UCase(Left(Text, PreLen)), UCase(PreList(x))) Then
                NoPrefixes = Right(Text, TextLen - PreLen)
            End If
    Next x

End Function
 
Upvote 0

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top