ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   mixing zip with zip+4 and then sorting (https://www.excelbanter.com/excel-discussion-misc-queries/203967-mixing-zip-zip-4-then-sorting.html)

JWCrosby

mixing zip with zip+4 and then sorting
 
I have a zip code column that has both standard zips (5 digits) and zip +4
(00000-0000). When I sort by zip it sorts all the 5-digit zips separately
(at the beginning) from the zip+4. How can I get it to sort and mix them
together in proper order?

Kevin B

mixing zip with zip+4 and then sorting
 
Create 2 side by side helper columns, one for the 5 digit zip prefix and
another for the 4 digit suffix. For the example I'll assume that the zip
codes start in D1:

In the first helper column enter the following formula to extract the 5
digit zip:

=LEFT(D1,5)

In the second helper column enter the following formula:

=IF(LEN(D1)=10,RIGHT(D1,4),"")

The IF statement only gets the 4 digits if the zip is 10 characters long.


Copy both formulas down to the last address in your table.

Now when you do your sort sort by the 5 digit zip formula column as your
primary and the 4 digit zip formula column as your secondary.

Hope this helps.
--
Kevin Backmann


"JWCrosby" wrote:

I have a zip code column that has both standard zips (5 digits) and zip +4
(00000-0000). When I sort by zip it sorts all the 5-digit zips separately
(at the beginning) from the zip+4. How can I get it to sort and mix them
together in proper order?


David McRitchie

mixing zip with zip+4 and then sorting
 
You want to format the column as text (string data), to fix what you have, see
Rearranging Data in Columns (join.htm), subtopic ...
Fix up for 5 digit US zip codes (#fixUSzip5)
http://www.mvps.org/dmcritchie/excel/join.htm#fixUSzip5

You can enter zip code as 09876- and it will be a text,
but formatting the column ahead of time as text is best.
--
HTH,
David McRitchie, Microsoft MVP -- Excel
My Excel Pages: http://www.mvps.org/dmcritchie/excel/excel.htm

"JWCrosby" wrote...
I have a zip code column that has both standard zips (5 digits) and zip +4
(00000-0000). When I sort by zip it sorts all the 5-digit zips separately
(at the beginning) from the zip+4. How can I get it to sort and mix them
together in proper order?



All times are GMT +1. The time now is 06:53 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com