sorting ZIP codes

K

KD

I am trying to sort a list of zip codes which contains some
regular 5-digit codes and some ZIP+4 (9 digits). The +4 ZIP
codes come out at the end, rather than being sorted in with
the others. Does anyone know how I can do this?
 
P

Paul Corrado

KD,

Easiest way is a helper column with the formula

=LEFT(A1,5)

and then sort on that column.

You can delete that when you are done.

PC
 
H

Harlan Grove

Easiest way is a helper column with the formula

=LEFT(A1,5)

and then sort on that column.

You can delete that when you are done.

Given the symptoms the OP mentions, either 5-digit zip codes are numbers
formatted with leading zeros while the 9-digit zip codes are text, or all are
numbers formatted with leading zeros. Using LEFT alone wouldn't help in the
former case, and using only the 5-digit zip code to sort could lead to anomalies
in adjacent 9-digit zip codes. The OP should use

=IF(ISNUMBER(A1),TEXT(A1*IF(LEN(A1)<=5,10000,1),"00000\-0000"),
LEFT(A1&"-0000",10))
 

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