Forum Discussion
Help to use TRIM or Left & RIGHT to extract TEXT
Hi,
I have a list of data files, the short form code of the service provider is contained in the file name. I wish to use this to then sort and follow up by service provider. The file name lengths can differ.
Can someone please assist in helping extract the service provider code from the filename?
Thank you kindly for any assistance.
You may try the following macro to get the service providers in column B.
Sub FindServiceProvider() Dim lr As Long Dim rng As Range Dim cel As Range Dim Matches As Object Application.ScreenUpdating = False lr = Cells(Rows.Count, 1).End(xlUp).Row Set rng = Range("A2:A" & lr) With CreateObject("VBScript.RegExp") .Global = False .Pattern = "[A-Z]{3,}" For Each cel In rng If .Test(cel) Then Set Matches = .Execute(cel.Value) cel.Offset(0, 1).Value = Matches(0) End If Next cel End With Application.ScreenUpdating = True End SubIn the attached, click the button called "Get Service Providers" to run the code.
9 Replies
- Subodh_Tiwari_sktneerSilver Contributor
You may try the following macro to get the service providers in column B.
Sub FindServiceProvider() Dim lr As Long Dim rng As Range Dim cel As Range Dim Matches As Object Application.ScreenUpdating = False lr = Cells(Rows.Count, 1).End(xlUp).Row Set rng = Range("A2:A" & lr) With CreateObject("VBScript.RegExp") .Global = False .Pattern = "[A-Z]{3,}" For Each cel In rng If .Test(cel) Then Set Matches = .Execute(cel.Value) cel.Offset(0, 1).Value = Matches(0) End If Next cel End With Application.ScreenUpdating = True End SubIn the attached, click the button called "Get Service Providers" to run the code.
- calof1Iron Contributor
Thank you again for your assistance, very much appreciated. Works perfectly.
Many thanks,
- Subodh_Tiwari_sktneerSilver Contributor
You're welcome calof1! Glad it worked as desired.