Need Macro to pull out Zip Code

ADeYoung

Board Regular
Joined
Jun 28, 2004
Messages
113
Need a Macro that will pull out a zip code from a cell here is the example:

Address: 400 NE 3rd St City: Prineville County: Crook County State: OR Zip code: 97754-1921

This is imported into excel as one cell...I want to pull out and sort by zip code, but because some only have 5 didgets and others 10, I have failed at trying to pull it out.
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Here's quick thing that might help you.

Try using text to columns, from the tool menu.

Set you delimiter as ":" and run it on the column. If the zip code: is always your last value, it should dump it into it's own cell. You might have some alignment issues, if the number of : fluctuates.

HTH.
 
Upvote 0
If this is the exact format you could try doing Data>Text to Columns... twice

First seperate address parts out with ':' as a delimiter.

Then seperate the zip codes with'-' as a delimeter.
 
Upvote 0
This macro will run on one cell and replace the contents with everything after the last : and assumes a space after the colon that is ignored as well.

Code:
Sub FindZip()
Dim length As Integer, i As Integer
data = ActiveCell.Value
For i = Len(data) To 1 Step -1
    If Mid(data, i, 1) = ":" Then
        length = i
        Exit For
    End If
Next i
data = Mid(data, length + 2, Len(data) - length)
ActiveCell.Value = data
End Sub
 
Upvote 0
I was trying to figure out this dilemma by using the RIGHT and LEN functions combined. I gave up and had a stroke of dumb luck befall me when I tried something else. I know this probably isn't what you want to do. But if you just want the Zip Codes to be shown, you could you the FIND/REPLACE option. Press CTRL+H and in the FIND field type "*: " (do not include the "s but make sure to include the space after the colon). This will remove everything except the ZipCode.
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,718
Members
452,939
Latest member
WCrawford

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