How to extract the middle of a string?

thewiseguy

Well-known Member
Joined
May 23, 2005
Messages
956
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a long list of products which contain multiple pieces of information in the string. I need to "clean up" the string of text and so I only need some of the information to be displayed.

Here is an example of the data that needs to be cleaned: Maxlite 100W LED T2 Architectural AreaLight 4K 120/277 Slip Fitter Mount

Here is what I would like the output to be: 100W LED T2 Architectural AreaLight

Each line of data is some variation of this. The first word is ALWAYS the manufacturer and can be removed.
Each line of data always has some variation of "4K." It could be 35K, 4K, 65K, but it will always end in "K."

Is there a formula I can use to clean up a few hundred lines of data as shown above?

Many thanks in advance!
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Book3.xlsx
AB
1Maxlite 100W LED T2 Architectural AreaLight 4K 120/277 Slip Fitter Mount100W LED T2 Architectural AreaLight
2Maxlite 40W LED T9 Architectural AreaLight 65K 120/277 Slip Fitter Mount40W LED T9 Architectural AreaLight
Sheet908
Cell Formulas
RangeFormula
B1:B2B1=TRIM(MID(SUBSTITUTE(LEFT(A1,SEARCH("?K ",A1)-2)," ",REPT(" ",LEN(A1)),1),LEN(A1),LEN(A1)))

I would actually use this slight variation of jtakw's nifty suggestion:

=TRIM(MID(SUBSTITUTE(LEFT(A2,FIND("K",A2)-3)," ",REPT(" ",LEN(A2)),1),LEN(A2),LEN(A2)))

Yeah, I shouldn't have used the wild card "?" in my formula which forced the SEARCH, but I would Definitely Keep the Space after the K like "K "

Book3.xlsx
AB
1Maxlite 100W LED T2 Architectural AreaLight 4K 120/277 Slip Fitter Mount100W LED T2 Architectural AreaLight
2Maxlite 40W LED T9 Architectural AreaLight 65K 120/277 Slip Fitter Mount40W LED T9 Architectural AreaLight
Sheet908
Cell Formulas
RangeFormula
B1:B2B1=TRIM(MID(SUBSTITUTE(LEFT(A1,FIND("K ",A1)-3)," ",REPT(" ",LEN(A1)),1),LEN(A1),LEN(A1)))


As I said in Post # 4, if the Manufacturer has more than 1 word and/or the # of digits before K (eg. 65K) exceeds 2 digits, I can adjust the formula to accommodate.
 
Upvote 0
Another UDF to possibly consider.
I don't know if it is possible to have an example like the last one below (or rows 7 or 8) but most of the other suggestions (I didn't test them all) return nothing or an error for that one.

VBA Code:
Function Description(s As String) As String
  With CreateObject("VBScript.RegExp")
    .Pattern = "\b\d+W .+?(?= \d+K )"
    If .Test(s) Then Description = .Execute(s)(0)
  End With
End Function

thewiseguy.xlsm
AB
1
2Maxlite 100W LED T2 Architectural AreaLight 4K 120/277 Slip Fitter Mount100W LED T2 Architectural AreaLight
3Maxlite 40W LED T9 Architectural AreaLight 65K 120/277 Slip Fitter Mount40W LED T9 Architectural AreaLight
4Maxlite 28W LED Adjustable WallPack 4K 120/27728W LED Adjustable WallPack
5Maxlite 2000W LED Xlarge Flood 4K 120/277 Slip Fitter Mount2000W LED Xlarge Flood
6Maxlite 9W LED Xlarge Flood 400K 120/277 Slip Fitter Mount9W LED Xlarge Flood
7 
8Nothing matches here 
9Max lite 28W LED Adjustable WallPack 4K 120/27728W LED Adjustable WallPack
10Max 4 lite 100W LED T2 Architectural AreaLight with long description 4K 120/277 Slip Fitter Mount100W LED T2 Architectural AreaLight with long description
11Triple-K 28W LED Adjustable WallPack 4K 120/27728W LED Adjustable WallPack
Sheet1
Cell Formulas
RangeFormula
B2:B11B2=Description(A2)
 
Upvote 0

Forum statistics

Threads
1,215,438
Messages
6,124,873
Members
449,192
Latest member
MoonDancer

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