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

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,252
Office Version
  1. 2016
Platform
  1. Windows
Could something like this work for you?

=IF(LEN(A1)>5,TEXT(A1,"00000-0000"),TEXT(A1,"00000"))
 

capparfrank

New Member
Joined
Feb 11, 2011
Messages
41
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:
#####
 

FryGirl

Well-known Member
Joined
Nov 11, 2008
Messages
1,252
Office Version
  1. 2016
Platform
  1. Windows
Sorry I did miss the part about conditional formatting
 

Forum statistics

Threads
1,141,018
Messages
5,703,757
Members
421,314
Latest member
Mooncake1

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
Top