Identify and extract postcode from address

dianeblackfamily

New Member
Joined
Jul 15, 2012
Messages
20
I wonder can anyone help?

Column D contains a complete address eg
60 Braugham Road, Wallasey, Merseyside CH46 1LP

I would like to be able to extract the postcode into column E, and then the address into columns F, G, H etc so that I can use the data for mailmerge docs. Is there a forumula or a macro that can be used to identify and extract the postcode? The postcode will usually be either one or two letters with one or two numbers, then a number and two letters. eg it might be as above or B6 9XF etc.

Any suggestions gratefully received!
 
Could you possibly explain how it works please?

Yes certainly.

The Post Code only has one blank in it and you're therefore interested in the space before the Post Code.

LEN(A2)-LEN(SUBSTITUTE(A2," ",""))-1 determines the index of that space by subtracting 1 and the "length of the string minus spaces" from the "length of the string".
Subtracting the "length of the string minus spaces" from the "length of the string" gives the number of spaces in the string.

SUBSTITUTE(A2," ",REPT(" ",99),LEN(A2)-LEN(SUBSTITUTE(A2," ",""))-1)
Replaces the last but one space in the string with 99 spaces, so we then have a string with a block of 99 spaces in the middle.

For the Town/County we want the left hand side of the string and for the Post Code we want the right hand side of the string.
In these cases we use Left( --string-- ,99) and Right( --string-- ,99) to extract the relevant part.

Finally TRIM is used to remove the trailing/leading spaces.

Alternatively, if you had remained with using Ricks formula to extract the Post Code and you had put that formula in Cell C2, you could have used the following formula in E2:-
Code:
=LEFT(A2,FIND(C2,A2)-2)
to extract the Town/County in to cell E2.

FIND(C2,A2) finds the position of the Post Code in the string and a further 2 is subtracted from that position to arrive at the character length of the Town/County.

hth
 
Upvote 0

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
If you want to extract the last two substrings without checking if it is a real postcode or not, try this shorter formula:

In B2:

=TRIM(RIGHT(SUBSTITUTE(A2," ",REPT(" ",8)),16))

In C2:

=SUBSTITUTE(A2," "&B2,"")
 
Upvote 0
@babulalghandi

Pleased to have helped solve your problem.

Your inbox for Private messages is full so I can't send you a PM!
 
Upvote 0

Forum statistics

Threads
1,223,234
Messages
6,170,891
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