SOLVED

Help to use TRIM or Left & RIGHT to extract TEXT

%3CLINGO-SUB%20id%3D%22lingo-sub-1240182%22%20slang%3D%22en-US%22%3EHelp%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1240182%22%20slang%3D%22en-US%22%3E%3CP%3EHi%2C%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20a%20list%20of%20data%20files%2C%20the%20short%20form%20code%20of%20the%20service%20provider%20is%20contained%20in%20the%20file%20name.%20I%20wish%20to%20use%20this%20to%20then%20sort%20and%20follow%20up%20by%20service%20provider.%20The%20file%20name%20lengths%20can%20differ.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20someone%20please%20assist%20in%20helping%20extract%20the%20service%20provider%20code%20from%20the%20filename%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20kindly%20for%20any%20assistance.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1240182%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EAdmin%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EBI%20%26amp%3B%20Data%20Analysis%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ECharting%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EDeveloper%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20for%20web%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EExcel%20on%20Mac%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EOffice%20365%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPower%20BI%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3ETraining%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EUser%20Adoption%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1240457%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1240457%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20may%20try%20the%20following%20macro%20to%20get%20the%20service%20providers%20in%20column%20B.%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESub%20FindServiceProvider()%0ADim%20lr%20%20%20%20%20%20As%20Long%0ADim%20rng%20%20%20%20%20As%20Range%0ADim%20cel%20%20%20%20%20As%20Range%0ADim%20Matches%20As%20Object%0A%0AApplication.ScreenUpdating%20%3D%20False%0A%0Alr%20%3D%20Cells(Rows.Count%2C%201).End(xlUp).Row%0ASet%20rng%20%3D%20Range(%22A2%3AA%22%20%26amp%3B%20lr)%0A%0AWith%20CreateObject(%22VBScript.RegExp%22)%0A%20%20%20%20.Global%20%3D%20False%0A%20%20%20%20.Pattern%20%3D%20%22%5BA-Z%5D%7B3%2C%7D%22%0A%20%20%20%20For%20Each%20cel%20In%20rng%0A%20%20%20%20%20%20%20%20If%20.Test(cel)%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20Set%20Matches%20%3D%20.Execute(cel.Value)%0A%20%20%20%20%20%20%20%20%20%20%20%20cel.Offset(0%2C%201).Value%20%3D%20Matches(0)%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Next%20cel%0AEnd%20With%0A%0AApplication.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIn%20the%20attached%2C%20click%20the%20button%20called%20%22Get%20Service%20Providers%22%20to%20run%20the%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1245647%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1245647%22%20slang%3D%22en-US%22%3E%3CP%3Ehi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%20again%20for%20your%20assistance%2C%20very%20much%20appreciated.%20Works%20perfectly.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1245703%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1245703%22%20slang%3D%22en-US%22%3E%3CP%3EYou're%20welcome%20%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E!%20Glad%20it%20worked%20as%20desired.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1245745%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1245745%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20tried%20replicating%20this%20to%20my%20spreadsheet.%20The%20output%20i%20wish%20to%20place%20the%20service%20provider%20is%20Column%20X%2C%20looking%20at%20the%20macro%20i%20believe%20i%20need%20to%20update%20the%20below%20section%20from%20to%20say%2024%20(new%20Column%20number).%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Ecel.Offset(0%2C%202)%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EGiven%20the%20information%20is%20still%20column%20D%2C%20i%20am%20guessing%20i%20change%20the%20below%20from%20A%20to%20D%3F%3C%2FP%3E%3CP%3ESet%20rng%20%3D%20Range(%22A2%3AA%22%20%26amp%3B%20lr)%3C%2FP%3E%3CP%3EWith%20CreateObject(%22VBScript.RegExp%22)%3CBR%20%2F%3E.Global%20%3D%20False%3CBR%20%2F%3E.Pattern%20%3D%20%22%5BA-Z%5D%7B3%2C%7D%22%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWould%20i%20need%20to%20update%20anything%20else%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMany%20thanks%2C%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1245758%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1245758%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20added%20comments%20in%20the%20following%20code%20which%20would%20help%20you%20to%20tweak%20the%20code%20as%20per%20your%20requirement.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESub%20FindServiceProvider()%0ADim%20lr%20%20%20%20%20%20As%20Long%0ADim%20r%20%20%20%20%20%20%20As%20Long%0ADim%20rng%20%20%20%20%20As%20Range%0ADim%20cel%20%20%20%20%20As%20Range%0ADim%20Matches%20As%20Object%0A%0AApplication.ScreenUpdating%20%3D%20False%0A%0A'Assuming%20Pcontrol%20Codes%20are%20in%20column%20A%0A'then%20finding%20the%20last%20row%20with%20data%20in%20column%20A%0Alr%20%3D%20Cells(Rows.Count%2C%20%22A%22).End(xlUp).Row%0A%0A'Setting%20the%20Pcontrol%20Codes%20Range%20in%20column%20A%0ASet%20rng%20%3D%20Range(%22A2%3AA%22%20%26amp%3B%20lr)%0A%0A%0AWith%20CreateObject(%22VBScript.RegExp%22)%0A%20%20%20%20.Global%20%3D%20False%0A%20%20%20%20.Pattern%20%3D%20%22%5BA-Z%5D%7B3%2C%7D%22%0A%20%20%20%20For%20Each%20cel%20In%20rng%0A%20%20%20%20%20%20%20%20r%20%3D%20cel.Row%0A%20%20%20%20%20%20%20%20If%20.Test(cel)%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20Set%20Matches%20%3D%20.Execute(cel.Value)%0A%20%20%20%20%20%20%20%20%20%20%20%20'Placing%20the%20Service%20Provider%20in%20the%20destination%20cell%2C%20in%20this%20case%20column%20B%0A%20%20%20%20%20%20%20%20%20%20%20%20'If%20you%20want%20to%20write%20the%20Service%20Provider%20say%20in%20Column%20D%2C%0A%20%20%20%20%20%20%20%20%20%20%20%20'use%20Cells(r%2C%20%22D%22).Value%20in%20the%20following%20line%0A%20%20%20%20%20%20%20%20%20%20%20%20Cells(r%2C%20%22B%22).Value%20%3D%20Matches(0)%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Next%20cel%0AEnd%20With%0A%0AApplication.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1248109%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1248109%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again%20for%20the%20help.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%20have%20changed%20the%20references%20as%20required%2C%20however%20i%20have%20noticed%20that%20when%20i%20run%20the%20macro%20it%20comes%20with%20a%20message%20saying%20to%20define%20the%20variable.%20I%20am%20new%20to%20VBA%20but%20think%20it%20has%20to%20do%20with%20the%20option%20Explicit%2C%20do%20i%20need%20to%20add%20a%20line%20to%20say%20which%20tab%20it%20refers%20to%3F%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22calof1_0-1585003252488.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F179014iFEAA4BA1767EAA9E%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22calof1_0-1585003252488.png%22%20alt%3D%22calof1_0-1585003252488.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22calof1_1-1585003364009.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F179015i384B0BA003823860%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22calof1_1-1585003364009.png%22%20alt%3D%22calof1_1-1585003364009.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20is%20adding%20to%20a%20tab%20called%20%22P135%20-%20Import%20Register%22%2C%20is%20there%20a%20way%20to%20define%20this%20to%20solve%20the%20error%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again%20for%20your%20help%2C%20and%20apologies%20for%20so%20many%20questions.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1248588%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1248588%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EIf%20you%20look%20at%20the%20latest%20tweaked%20code%20(with%20added%20comments)%2C%20you%20missed%20a%20variable%20declaration%20and%20one%20line%20of%20code%20as%20well%20i.e.%20you%20partially%20tweaked%20the%20original%20code.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAfter%20the%20tweak%2C%20your%20final%20code%20should%20be%20like%20this...%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESub%20FindServiceProvider()%0ADim%20lr%20%20%20%20%20%20As%20Long%0ADim%20r%20%20%20%20%20%20%20As%20Long%0ADim%20rng%20%20%20%20%20As%20Range%0ADim%20cel%20%20%20%20%20As%20Range%0ADim%20Matches%20As%20Object%0A%0AApplication.ScreenUpdating%20%3D%20False%0A%0Alr%20%3D%20Cells(Rows.Count%2C%20%22D%22).End(xlUp).Row%0ASet%20rng%20%3D%20Range(%22D2%3AD%22%20%26amp%3B%20lr)%0A%0AWith%20CreateObject(%22VBScript.RegExp%22)%0A%20%20%20%20.Global%20%3D%20False%0A%20%20%20%20.Pattern%20%3D%20%22%5BA-Z%5D%7B3%2C%7D%22%0A%20%20%20%20For%20Each%20cel%20In%20rng%0A%20%20%20%20%20%20%20%20r%20%3D%20cel.Row%0A%20%20%20%20%20%20%20%20If%20.Test(cel)%20Then%0A%20%20%20%20%20%20%20%20%20%20%20%20Set%20Matches%20%3D%20.Execute(cel.Value)%0A%20%20%20%20%20%20%20%20%20%20%20%20Cells(r%2C%20%22X%22).Value%20%3D%20Matches(0)%0A%20%20%20%20%20%20%20%20End%20If%0A%20%20%20%20Next%20cel%0AEnd%20With%0A%0AApplication.ScreenUpdating%20%3D%20True%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1250858%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1250858%22%20slang%3D%22en-US%22%3E%3CP%3EHi%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F394231%22%20target%3D%22_blank%22%3E%40Subodh_Tiwari_sktneer%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EMy%20apologies%20for%20missing%20the%20line%20of%20code%2C%20i%20have%20now%20updated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThanks%20again%20for%20all%20your%20assistance.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAll%20the%20best.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1251144%22%20slang%3D%22en-US%22%3ERe%3A%20Help%20to%20use%20TRIM%20or%20Left%20%26amp%3B%20RIGHT%20to%20extract%20TEXT%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1251144%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F364226%22%20target%3D%22_blank%22%3E%40calof1%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3ENo%20problem!%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Frequent Contributor

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.

9 Replies
Highlighted
Best Response confirmed by calof1 (Frequent Contributor)
Solution

@calof1 

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.

 

 

Highlighted

hi@Subodh_Tiwari_sktneer 

 

Thank you again for your assistance, very much appreciated. Works perfectly.

 

Many thanks,

Highlighted

You're welcome @calof1! Glad it worked as desired.

Highlighted

Hi@Subodh_Tiwari_sktneer 

 

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,

Highlighted

@calof1 

I have added comments in the following code which would help you to tweak the code as per your requirement.

 

Sub FindServiceProvider()
Dim lr      As Long
Dim r       As Long
Dim rng     As Range
Dim cel     As Range
Dim Matches As Object

Application.ScreenUpdating = False

'Assuming Pcontrol Codes are in column A
'then finding the last row with data in column A
lr = Cells(Rows.Count, "A").End(xlUp).Row

'Setting the Pcontrol Codes Range in column A
Set rng = Range("A2:A" & lr)


With CreateObject("VBScript.RegExp")
    .Global = False
    .Pattern = "[A-Z]{3,}"
    For Each cel In rng
        r = cel.Row
        If .Test(cel) Then
            Set Matches = .Execute(cel.Value)
            'Placing the Service Provider in the destination cell, in this case column B
            'If you want to write the Service Provider say in Column D,
            'use Cells(r, "D").Value in the following line
            Cells(r, "B").Value = Matches(0)
        End If
    Next cel
End With

Application.ScreenUpdating = True
End Sub
Highlighted

Hi@Subodh_Tiwari_sktneer 

 

Thanks again for the help.

 

I have changed the references as required, however i have noticed that when i run the macro it comes with a message saying to define the variable. I am new to VBA but think it has to do with the option Explicit, do i need to add a line to say which tab it refers to?

calof1_0-1585003252488.png

 

calof1_1-1585003364009.png

 

 

This is adding to a tab called "P135 - Import Register", is there a way to define this to solve the error?

 

Thanks again for your help, and apologies for so many questions.

Highlighted

@calof1 

If you look at the latest tweaked code (with added comments), you missed a variable declaration and one line of code as well i.e. you partially tweaked the original code.

 

After the tweak, your final code should be like this...

Sub FindServiceProvider()
Dim lr      As Long
Dim r       As Long
Dim rng     As Range
Dim cel     As Range
Dim Matches As Object

Application.ScreenUpdating = False

lr = Cells(Rows.Count, "D").End(xlUp).Row
Set rng = Range("D2:D" & lr)

With CreateObject("VBScript.RegExp")
    .Global = False
    .Pattern = "[A-Z]{3,}"
    For Each cel In rng
        r = cel.Row
        If .Test(cel) Then
            Set Matches = .Execute(cel.Value)
            Cells(r, "X").Value = Matches(0)
        End If
    Next cel
End With

Application.ScreenUpdating = True
End Sub

 

 

 

 

Highlighted

Hi@Subodh_Tiwari_sktneer 

 

My apologies for missing the line of code, i have now updated.

 

Thanks again for all your assistance.

 

All the best.

Highlighted