Extract Postal Codes from addresses

excel_1317

Board Regular
Joined
Jun 28, 2010
Messages
212
I have around 1000 addresses of about 60 different countries. These addresses are split into 5 columns. Need to extract postal codes in a new column.
Excel Workbook
ABCDE
1Attn Of/Address Line 1Address Line 2Address Line 3Address Line 4Address Line 5/Country Name
22040 Main Street14th FloorIrvine, CA 92614U.S.A.
3Ruppmannstrasse 27D-70565 StuttgartGermany
4Aeschenvorstadt 24P.O. Box 3184010 BaselSwitzerland
516, Akadimias str.10671 AthensGreece
61725 Duke St., Suite 240Alexandria, VA 22314U.S.A.
7Bavariaring 2080336 MunchenGermany
867 Hayarkon str.Bnei Brak 51206Israel
91185 Avenue of the AmericasNew York, NY 10036U.S.A.
10401 Congress Ave., Suite 3200Austin, Texas 78701U.S.A.
11109, Sector 44, Gurgaon 122 00National Capital RegionIndia
122-3 Fuji BldgMarunouchi 3-ChomeChiyoda-KuTokyo 100-0005Japan
1313 Haraduf Str.Omer 84965Israel
1454 Derech Bet Lechem str.Jerusalem 93504Israel
15Lackenbach Siegel BuildingOne Chase RoadScarsdale, New York 10583U.S.A.
16Mail Box No. 15Thai Thinh Post Office35 Thai Thinh StreetDong Da District, HanoiVietnam
171040 Avenue of the AmericasNew York, NY 10018-3738U.S.A.
18Kibutz LahavMobile Post Office 85335Israel
1914 David Elazar str. 6Beer Sheva 84509Israel
2028 Hazait Str.Meitar 85025Israel
21B-6/10, Safdarjung Enclave,New Delhi - 110 029India
22POSTFACH 111206900 HEIDELBERG 1Germany
23Riverfront Office ParkOne Main StreetEleventh FloorCambridge, MA 02142U.S.A.
241500 Norwest Financial Center7900 Xerxes Avenue SouthBloomington, Minnesota55431-1194U.S.A.
2562 Rue de Bonnel69448 Lyon Cedex 03France
Sheet3
Excel 2010


Postal code can be in Column A, B C or D. Column E has the country. Please help me extracting the postal codes in a new column F.
 
With your data sheet active press Alt+F8, select the Extract_PC macro and click Run.

Make sure you test in a copy of your workbook.


Great!!!! It works like a charm. Your comments are correct. The logic doesnot work for all the cases because of data entry issues. But it is fine.. Thanks again..
 
Upvote 0

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Great!!!! It works like a charm. Your comments are correct. The logic doesnot work for all the cases because of data entry issues. But it is fine.. Thanks again..
I'm glad we got something useful. :)
I must admit that when I read your first post I wasn't expecting a good outcome, at least in such a short time.

If you can subsequently decide on any further country code patterns/rules like in post #7, they should be able to be added to the Countries and PCPatterns strings near the start of the code.
 
Upvote 0
Hi

I noticed that for the UK you expect a format of 7 characters with the 4th character being a space!
Quite the contrary see :-
Valid UK Postcode formats

The corresponding change to the Regex pattern would be:-
Code:
                              "\b[0-9A-Z]{2,4} [0-9A-Z]{3}\b," & _[\code]

hth
 
Last edited:
Upvote 0

Forum statistics

Threads
1,216,101
Messages
6,128,843
Members
449,471
Latest member
lachbee

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