Extracting Numeric / Alpha-Numeric data from Cells using VBA

danburgan

New Member
Joined
Sep 10, 2014
Messages
3
Good Afternoon All,

I am trying to automate a task to take data from one column and copy a district identifier to another. The data and the expected outcome are below.

DistrictOutput
Congressional District 11
Congressional District 22
Congressional District 33
Congressional District 44
Congressional District 55
State Senate District 2121
District 2121
District 30A30A
District 30B30B
District 31A31A
5th Judicial Circuit 5
5th Judicial Circuit 5
Legislative District 21 21

<colgroup><col><col></colgroup><tbody>
</tbody>


I can easily pull data from the first few rows using Mid, but I have three different scenarios to look at and the amount of data in the sheet is variable.

Any assistance with this is greatly appreciated.

Dan
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
Since I just noticed that there are some strings with numbers at the beginning, I think this one will work better.

=LEFT(MID(A1,MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&1234567890)),LEN(A1)),FIND(" ",A1))
 
Upvote 0
AlKey,

So close and thank you for the assistance.

When I add the formula and view results we catch 2 out of 3 of the scenarios.

DistrictOutput
Congressional District 11
Congressional District 22
Congressional District 33
Congressional District 44
Congressional District 55
State Senate District 2121
District 2121
District 30A30A
District 30B30B
District 31A31A
5th Judicial Circuit5th
5th Judicial Circuit5th
Legislative District 2121

<tbody>
</tbody>


The last is removing the "th" or "st" from the number values. These would show up as lowercase always.
 
Upvote 0
Assuming your numbers are in either the first or last "word" (as all your examples show), then this formula should do what you want...

=IF(ISNUMBER(-LEFT(A2)),""&-LOOKUP(0,-LEFT(A2,ROW(INDEX(A:A,1):INDEX(A:A,LEN(A2))))),TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",99)),99)))
 
Upvote 0
Rick and AlKey. Thank you both. I was making this much more difficult than what it needed to be.

Thanks again.
 
Upvote 0

Forum statistics

Threads
1,214,622
Messages
6,120,585
Members
448,972
Latest member
Shantanu2024

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