Link to home
Start Free TrialLog in
Avatar of Saqib Husain
Saqib HusainFlag for Pakistan

asked on

Formula to extract numbers from text

I have text strings in the form

0' - Start of straight line, Road R-6 RD 0'
397' - Road R-5 RD 0', Start of straight line
9234' - Road R-29 RD 6247', End of road
6141' - Road R-1 RD 9233', Road R-29 RD 6239', End of road
739' - Road R-149 RD 0'
2534' - End of road, Road R-40 RD 2267'
0' - Start of straight line, Road R-1 RD 0', Road R-20 RD 0'


I need to extract the R- numbers and the RD values as shown in the attached file. Excel formula preferred but VBA is also acceptable.
Extract-number-and-values.xlsx
Avatar of scsyme
scsyme
Flag of United Kingdom of Great Britain and Northern Ireland image

As a start you can put the following in B2 of your example and copy down:
=MID(A2,FIND("R-",A2)+2,FIND(" ",A2,FIND("R-",A2))-FIND("R-",A2)-2)

Open in new window


and the following into C2 of your example and copy down
=MID(A2,FIND("RD ",A2)+3,FIND("'",A2,FIND("RD ",A2))-FIND("RD ",A2)-3)

Open in new window


Columns D and E represent a second pair of R- and RD in the same data. Will they always occur in pairs? Is there a limit to the number of pairs per cell in column A?
Avatar of Saqib Husain

ASKER

Thanks for the formulas. Yes they will always be in pairs. I have two at the moment and I think that the maximum could be 4.
SOLUTION
Avatar of Professor J
Professor J

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I am just curious how this can be done using formula instead of UDF
Avatar of Professor J
Professor J

Flora,

It is possible with formula, but the formula would be too lengthy, so if UDF does the job, why waste time with formula?

if you want this by formula, i suggest you open a new question.
ProfJimJam is correct in that trying to do this in one long formula for the fourth instance (for example) would be too lengthy.
If you're happy to put up with some additional columns then this can be simplified somewhat as seen in the attached.

Hope that helps.
Extract-number-and-values--ss-.xlsx
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That's a pretty nifty solution. Nothing to add :-)
Found a preferred solution.