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.

21117-2111
21117
21234
20737-2073
21133-2113
21133-2113
20853
20850


<colgroup><col></colgroup><tbody>
</tbody>
Can I have some help, please? Thank you.
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
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,214,945
Messages
6,122,395
Members
449,081
Latest member
JAMES KECULAH

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