Trim Postcode

abbaddon223

Registered User.
Local time
Yesterday, 18:26
Joined
Mar 13, 2010
Messages
162
Hi all,

If anyone can help I'd be very grateful!

I'm trying to trim a postcode (easy) so that only the first two letters are left (finding not easy).

The issue I have is:

AB21 4LF
S21 2RE

IE I'm after

AB
S

If I trim from left or right based on the a space and characters to remove, the postcodes with only 3 IN characters end up wiped out...

Thanks in advance...
 
left("S212RE", 2 + ( asc(mid(Ucase("S212RE"), 2,1)) < 64 ) )
S
left("AB214LF", 2 + ( asc(mid(Ucase("AB21 4LF"), 2,1)) < 64) )
AB

should work...
 
Hi,

Thanks for your response.

Would this work en-masse though? (IE I have 32K lines of data with all different postodes).

Thanks again.
 
here's another way

i think postcodes have to start with a letter and are either one or two letters for the postcode area.

IIf(IsNumeric(Mid([postcode],2,1)),Left([postcode],1),Left([postcode],2))
 
assuming your postcodes are guaranteed well formatted then you could use something like this idea - which needs a bit of further attention

Code:
if isnumeric(char2) then
   leftpart = left(postcode,1)
else
   leftpart = left(postcode,2)
end if

on reflection i see this is the same idea as G81 above
 
Last edited:
Hi,

Thanks for your response.

Would this work en-masse though? (IE I have 32K lines of data with all different postodes).

Thanks again.

YEs it should take for any and all postcodes the first (two) letters
 

Users who are viewing this thread

Back
Top Bottom