Extracting 1st 3-digits of postal code that begin with 0

P

Pcakes

I have to extract the first 3-digits of a postal code, currently using:

=LEFT(A1,3)

However, this will not pull correctly if the postal code begins with 0.

Example: 04587 will pull 458 instead of 045.

Any suggestions?
 
D

David Biddulph

Pcakes said:
I have to extract the first 3-digits of a postal code, currently using:

=LEFT(A1,3)

However, this will not pull correctly if the postal code begins with 0.

Example: 04587 will pull 458 instead of 045.

Any suggestions?

If you insert your codes as text, then your formula will work OK.

If your cell actually contains the number 4587, rather than the code 04587,
you might try
=IF(LEN(A1)=4,0&LEFT(A1,2),LEFT(A1,3))

If you have other formats than the 5 digits, expand the expression to suit.
 
M

Marcelo

Hi Pcakes,

I didn't understand your question if it is a text the formula works

the postal code data are formated as a text or value?


regards
Marcelo

"Pcakes" escreveu:
 
R

Roger Govier

Hi

It sounds as though the input of the code in the first instance needs to
have included a single quote in front to force it to be text '04587

You could use =LEFT("0"&A1,3)
 
P

Pcakes

They are custom formatted, as zipcode.

Marcelo said:
Hi Pcakes,

I didn't understand your question if it is a text the formula works

the postal code data are formated as a text or value?


regards
Marcelo

"Pcakes" escreveu:
 
R

Roger Govier

Hi
Thanks for the feedback, but I think David Biddulph gave a more useful
and generalised solution.
 
P

Pcakes

Thank you most helpful!

David Biddulph said:
If you insert your codes as text, then your formula will work OK.

If your cell actually contains the number 4587, rather than the code 04587,
you might try
=IF(LEN(A1)=4,0&LEFT(A1,2),LEFT(A1,3))

If you have other formats than the 5 digits, expand the expression to suit.
 
R

Ron Rosenfeld

I have to extract the first 3-digits of a postal code, currently using:

=LEFT(A1,3)

However, this will not pull correctly if the postal code begins with 0.

Example: 04587 will pull 458 instead of 045.

Any suggestions?

=LEFT(TEXT(A1,"00000"),3)


--ron
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top