formula to extract substring from text string

miconian

Well-known Member
Joined
Aug 18, 2004
Messages
769
I have a series of cells that contain text which looks like this:

blahblah blah blah blah BLAHBLAH line 23blahblahblah

The "23" is the relevant part. It's always a number, it could be from one to three digits long, and it always comes just to the right of "line" followed by a space.

I basically need to isolate that number and put it in another cell.

Seems to me the answer involves the use of FIND and MID. But what trips me up is the fact that the string I'm looking for is of variable length.

Any thoughts? Thanks so much for your help!
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Hi

One option:


Excel 2010
AB
4blahblah blah blah blah BLAHBLAH line 23blahblahblah23
5some rubbish line 999 and some more junk999
Sheet1
Cell Formulas
RangeFormula
B4=LOOKUP(1000,--MID(A4,SEARCH("line ",A4)+5,{1,2,3}))
 
Upvote 0
One way, maybe:

=IF(RIGHT(MID(A1,FIND("line ",A1)+5,3),1)>="a",--MID(A1,FIND("line ",A1)+5,2),--MID(A1,FIND("line ",A1)+5,3))
 
Upvote 0
I have a series of cells that contain text which looks like this:

blahblah blah blah blah BLAHBLAH line 23blahblahblah

The "23" is the relevant part. It's always a number, it could be from one to three digits long, and it always comes just to the right of "line" followed by a space.

I basically need to isolate that number and put it in another cell.

Seems to me the answer involves the use of FIND and MID. But what trips me up is the fact that the string I'm looking for is of variable length.

Any thoughts? Thanks so much for your help!
Is it possible that the text might include more than 1 substring of "line "?

It's better to post real examples that will give us a better idea of what we need to look for.
 
Upvote 0
Thanks, Firefly. Seems to work perfectly. Although some of the results are inexplicably underlined.

SpecialK, that might have worked too, although despite my 'blah' example, there are actually other numbers in the string I'm extracting from.
 
Upvote 0
Try...

=LOOKUP(9.99999999999999E+307,--LEFT(REPLACE(A2,1,SEARCH("line ",A2)+4,""),ROW(INDIRECT("1:"&LEN(A2)))))
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,140
Members
449,098
Latest member
Doanvanhieu

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