add a hyphen on a 9 digit zipcode

Chanoaguilas

New Member
Joined
Nov 19, 2018
Messages
1
Hi guys,

I am new to using excel. so here's what I'm trying to do:
Some US zip codes have 9 digits and I want to a Hyphen "-" after the first 5 digits in a column. However, the same column also includes 5 digit ones so I am trying to use =IF(LEN(a2)>5,(REPLACE(a2,6,0,"-"))) but I can't seem to get it right. It should like this.

[TABLE="width: 152"]
<colgroup><col></colgroup><tbody>[TR]
[TD]21117-2111[/TD]
[/TR]
[TR]
[TD]21117[/TD]
[/TR]
[TR]
[TD]21234[/TD]
[/TR]
[TR]
[TD]20737-2073[/TD]
[/TR]
[TR]
[TD]21133-2113[/TD]
[/TR]
[TR]
[TD]21133-2113[/TD]
[/TR]
[TR]
[TD]20853[/TD]
[/TR]
[TR]
[TD]20850

[/TD]
[/TR]
</tbody>[/TABLE]
Can I have some help, please? Thank you.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Can't you just concatenate as below?

Excel Workbook
AB
221117211121117-2111
32111721117
42123421234
520737207320737-2073
621133211321133-2113
721133211321133-2113
82085320853
92085020850
Sheet3
 
Upvote 0
If it is only the appearence you want to change then you could also just use conditional formatting using the formula =len(A2)>5 then under the custom number format use #####"-"####
 
Upvote 0
Here is another formula that you can consider...

=TEXT(A1,"[>99999]00000-0000;00000")
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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