zip code conditional formatting

greyhound

New Member
Joined
Dec 9, 2006
Messages
12
I have a column with zip codes, some 5 characters, some 9 characters. I need to write an if statment in conditinal formatting that will insert a dash after 5 characters if the length is 9 characters. This is my attempt but does not work:

=if(len(text) > 5, #####, #####-####)

Many thanks, greyhound
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Could something like this work for you?

=IF(LEN(A1)>5,TEXT(A1,"00000-0000"),TEXT(A1,"00000"))
 
Upvote 0
I think that in conditional formatting, you won't use an 'if' statment. Simply provide the condition to evaluate in formula.

If you want to create an if/else behavior, you need to create two rules.

so:

rule 1 formula:
= LEN($A$1) > 5

rule 1 format:
#####-####

rule 2 formula:
= LEN($A$1) <= 5

rule 2 format:
#####
 
Upvote 0
Sorry I did miss the part about conditional formatting
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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