Formula = If cell does not contain 15 characters, then highlight orange

westc4

Board Regular
Joined
Aug 1, 2012
Messages
89
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am sure this is an easy question, but I have not been able to get it to work for me. I have 5000+ rows that can contain both numbers, alpha and a mix of both. The column is formatted custom '000000000000000' (15). What I need is if the cell contains anything other than 15 (no spaces) characters highlight the cell to be orange (or any other color).

The first character could be alpha or number (never a zero), but the following 14 characters will always be a number.

Here is a sample set of data:
[TABLE="width: 212"]
<tbody>[TR]
[TD]022006000015582 Bad[/TD]
[/TR]
[TR]
[TD]030020000157510 Bad[/TD]
[/TR]
[TR]
[TD]320220000093166 Good[/TD]
[/TR]
[TR]
[TD]000004001100000 Bad[/TD]
[/TR]
[TR]
[TD]000000000163132 Bad[/TD]
[/TR]
[TR]
[TD]120180000103126 Good[/TD]
[/TR]
[TR]
[TD]200010000119899 Good[/TD]
[/TR]
[TR]
[TD]A00100000033408 Good
[/TD]
[/TR]
[TR]
[TD]003401400086119 Bad
[/TD]
[/TR]
[TR]
[TD]120180000102297 Good
[/TD]
[/TR]
[TR]
[TD]34014 00000 73023 Bad
[/TD]
[/TR]
[TR]
[TD]200010000119899 Good
[/TD]
[/TR]
[TR]
[TD]040010000095304 Bad
[/TD]
[/TR]
[TR]
[TD]CONS/460190000049100 Bad
[/TD]
[/TR]
[TR]
[TD]000000000163089 Bad
[/TD]
[/TR]
[TR]
[TD]28012 0000106955 Bad
[/TD]
[/TR]
[TR]
[TD]Thank you![/TD]
[/TR]
[TR]
[TD][/TD]
[/TR]
</tbody>[/TABLE]
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Just use Conditional Formatting, with a formula like:
Code:
=LEN(SUBSTITUTE($A1," ",""))=15
 
Last edited:
Upvote 0
Just use Conditional Formatting, with a formula like:
Code:
=LEN(SUBSTITUTE($A1," ",""))=15
The OP shows some cells with 15 digits and some interspersed spaces which would pass your test but which he has marked as bad. I think we need to know from the OP whether his good spaces are 15 characters long with no spaces.
 
Upvote 0
Thank you! I knew it should not be as difficult as I was making it.

I did change the formula a little to
Code:
=LEN($A1)<>15
This will highlight the cells that have more or less than the 15 characters and does not ignore the spaces.
 
Last edited:
Upvote 0
Sorry, I actually meant to say "<>15" instead of "=15", i.e.
Code:
=LEN(SUBSTITUTE($A1," ",""))<>15
Originally, I just had the LEN without the SUBSTITUTION part, but I thought that you said it needs to be 15 characters, not counting the spaces?
So are you telling me that if you have the number 1, with 13 spaces, and then another number 1, that would be OK?
The code with the SUBSTITUTE would catch and highlight that, but the code without it wouldn't.

Unless you are saying that you know for sure that there will ALWAYS be 15 non-space characters, and then you are just looking for extra spaces?
If that is the case, and you want to look for that and any values starting with a zero, then use:
Code:
=OR(LEN($A1)=15,LEFT($A1,1)="0")
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,176
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