Extract words and numbers from comples string (Excel 2010)

FredStimler

New Member
Joined
Jan 5, 2016
Messages
3
I converted a PDF file with important TAX rate information. It did not work very well so now I must grab values from the string into 3 different columns. An example string is "Agua Dulce 9.00% Los Angeles".

The first word (City) is from position 1 to where there are two blank spaces.
The rate is the first numeric on the page - grab the decimal and 2 more places
The last word (County) is the next word - to the end of the string.

I have used Find, Substitute, IsNumber, Search, MID and others but am confused on how to combine them here.
Thanks.
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
With
A1: containing the text to parse, in the format: text(containing spaces) followed by a number_in_percent_format followed by other text
Example: Agua Dulce 9.00% Los Angeles

These formulas return the
city
Code:
B1: =TRIM(LEFT(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))-1))

Rate
Code:
C1: =LOOKUP(99^99,--("0"&MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")),ROW($1:$10000))))

County
Code:
D1: =TRIM(MID(A1,SEARCH("%",A1)+1,LEN(A1)))

In that example, the formulas return:
Agua Dulce
0.09
Los Angeles

Is that something you can work with?
 
Upvote 0
Thank you Ron. The only issue I still have is that often the space for CITY is 20 characters before the Rate starts. You RATE and COUNTY formulas were perfect. How can I restrain the CITY so it stops at the first digit? Right now the City formula returns "Anaheim* 8.00% Orange" from the source cell of "Anaheim* 8.00% Orange". Thanks.
 
Upvote 0
I think the website replaced whatever is between "Anaheim" and "8" with an asterisk.
Can you find a way to put those values in or explain what goes there?
 
Upvote 0
For
Code:
A1: Anaheim                8.00% Orange
This formula returns: Anaheim
Code:
B1: =TRIM(LEFT(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))-1))

If you're seeing something else, then there's an issue with the data.
 
Upvote 0
Here's UDF which would get every part you need. The second argument (iPart) is the part number you need: 0 - city, 1 - rate, 2 - county. Just put the number you need.
Code:
Function GetPart$(s$, iPart%)
    With CreateObject("VBScript.RegExp")
        .IgnoreCase = True: .Pattern = "(.+?)(\d+(?:\.\d+)?%)(.+)": GetPart = .Execute(s)(0).SubMatches(iPart)
    End With
End Function
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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