Forum Discussion
Help to use TRIM or Left & RIGHT to extract TEXT
- Mar 19, 2020
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.
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 Sub
In the attached, click the button called "Get Service Providers" to run the code.
- calof1Mar 22, 2020Iron Contributor
Thank you again for your assistance, very much appreciated. Works perfectly.
Many thanks,
- Subodh_Tiwari_sktneerMar 22, 2020Silver Contributor
You're welcome calof1! Glad it worked as desired.
- calof1Mar 22, 2020Iron Contributor
I have tried replicating this to my spreadsheet. The output i wish to place the service provider is Column X, looking at the macro i believe i need to update the below section from to say 24 (new Column number).
cel.Offset(0, 2)
Given the information is still column D, i am guessing i change the below from A to D?
Set rng = Range("A2:A" & lr)
With CreateObject("VBScript.RegExp")
.Global = False
.Pattern = "[A-Z]{3,}"Would i need to update anything else?
Many thanks,