Extracting data from cell between text or just with text

dgrissam

New Member
Joined
Dec 29, 2018
Messages
3
I am needing to pull numbers from the middle of a cell. The problem is that the data is entered by many different people and none of them do it the same way. One cell could have “W/.5LWOP/2.75LS” another cell “N 2.5 LS 1.75 LC” another “N 5LS” yet another “N 4@99 1.5LC 2LS 2LU”. Some use spaces between other use "/" and some use a space. The numbers I need are preceding the LS in each cell (including the “.” If there is one)

I have been told to use RegEx in VBA, however i have little experience with VBA and no experience with RegEx.

I have been working on this for weeks any help would be greatly appreciated.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,

See how this works out for your data.

B1 formula extracts the number immediately before "LS" as is, result as Text,
C1 formula converts same result to Number in case for further math/comparison:


Book1
ABC
1W/.5LWOP/2.75LS2.752.75
2N 2.5 LS 1.75 LC2.52.5
3N 5LS55
4N 4@99 1.5LC 2LS 2LU22
5N 2.5 LS 1.75 LC2.52.5
6W/2.75LS.5LWOP2.752.75
Sheet436
Cell Formulas
RangeFormula
B1=TRIM(LEFT(RIGHT(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(LEFT(A1,FIND("LS",A1)),"L"," L"),"/"," "))," ",REPT(" ",100)),200),100))
C1=LEFT(RIGHT(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(LEFT(A1,FIND("LS",A1)),"L"," L"),"/"," "))," ",REPT(" ",100)),200),100)+0
 
Last edited:
Upvote 0
I think this formula will do what you want...

=LOOKUP(9E+99,--RIGHT(TRIM(LEFT(A1,FIND("LS",A1)-1)),ROW($1:$99)))
 
Last edited:
Upvote 0
Hi,

See how this works out for your data.

B1 formula extracts the number immediately before "LS" as is, result as Text,
C1 formula converts same result to Number in case for further math/comparison:

ABC
1W/.5LWOP/2.75LS2.752.75
2N 2.5 LS 1.75 LC2.52.5
3N 5LS55
4N 4@99 1.5LC 2LS 2LU22
5N 2.5 LS 1.75 LC2.52.5
6W/2.75LS.5LWOP2.752.75

<colgroup><col style="width: 25pxpx"><col><col><col></colgroup><thead>
</thead><tbody>
</tbody>
Sheet436

Worksheet Formulas
CellFormula
B1=TRIM(LEFT(RIGHT(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(LEFT(A1,FIND("LS",A1)),"L"," L"),"/"," "))," ",REPT(" ",100)),200),100))
C1=LEFT(RIGHT(SUBSTITUTE(TRIM(SUBSTITUTE(SUBSTITUTE(LEFT(A1,FIND("LS",A1)),"L"," L"),"/"," "))," ",REPT(" ",100)),200),100)+0

<thead>
</thead><tbody>
</tbody>

<tbody>
</tbody>
Thank you ... Thank you ... Thank you. Formula (C1) does exactly what i needed it to do. I should have posted in here weeks ago and could have saved some extra gray hairs. I never would have come up with that on my own. Thank you.
 
Upvote 0
Thank You Rick ... I just plugged your formula into my live data and it works perfectly. Sorry I was so excited when I saw the first post (and it worked) I almost missed yours. Thank you ... thank you ... thank you ... i wish i would have posted in this forum long ago to ask for help. There are people out there with far more knowledge then me.
 
Upvote 0
You're welcome, welcome to the forum.
 
Upvote 0

Forum statistics

Threads
1,214,918
Messages
6,122,252
Members
449,075
Latest member
staticfluids

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