Check if Cell contains x amount of numbers plus a letter

hmltnangel

Active Member
Joined
Aug 25, 2010
Messages
290
Office Version
  1. 365
Platform
  1. Windows
Just as it says on the tin folks.

Is there anyway to get excel 2010 to conditional format a cell if the cell contains (for instance) a six digit number followed by a letter? (123456A)?

thanks
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Just as it says on the tin folks.

Is there anyway to get excel 2010 to conditional format a cell if the cell contains (for instance) a six digit number followed by a letter? (123456A)?
Assuming the active cell is A1, give this Conditional Formatting formula a try...

=AND(ISNUMBER(-LEFT(A1,6)),ISTEXT(RIGHT(A1)))
 
Upvote 0
Assuming the active cell is A1, give this Conditional Formatting formula a try...

=AND(ISNUMBER(-LEFT(A1,6)),ISTEXT(RIGHT(A1)))
Actually, we need to also check the length of the value in the cell as well...

=AND(ISNUMBER(-LEFT(A1,6)),ISTEXT(RIGHT(A1)),LEN(A1)=7)
 
Upvote 0
Excellent, thanks :D

Seems to work fine. I have around 40 entries to check now nstead of 1600 .... massive time saver. thanks again.
 
Upvote 0
Seems to work fine.
I disagree. I have used that CF in my first screen shot below. As you can see, it has incorrectly highlighted the first 4 entries.

Excel Workbook
A
11DEC189
26985648
3123E45X
46 6
5569845R
CF1
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A11. / Formula is =AND(ISNUMBER(-LEFT(A1,6)),ISTEXT(RIGHT(A1)),LEN(A1)=7)Abc




Instead, I would suggest this CF formula.

Excel Workbook
A
11DEC189
26985648
3123E45X
46 6
5569845R
CF2
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A11. / Formula is =AND(MAX(ABS(52.5-CODE(MID(A1,ROW(INDIRECT("1:6")),1))))<5,ABS(77.5-CODE(UPPER(RIGHT(A1))))<13,LEN(A1)=7)Abc
 
Upvote 0
Thanks Peter,

I was just coming back to say id found errors in it :). Also a few changes to exactly whats needed, the numbers have to be exactly 7 digits with either one or two letters after it. If I can understand what each part of the code is doing, then I can make the amendment. I'll have a mess with it and see if I can make it work.
 
Upvote 0
the numbers have to be exactly 7 digits with either one or two letters after it.
Try this one.

Excel Workbook
A
18932658D
29865489Xy
31111E11X
46 6
5569 845R
65708845R
70000000RQ
823659874Z
9
10
CF3
Cells with Conditional Formatting
CellConditionCell FormatStop If True
A11. / Formula is =AND(MAX(ABS(52.5-CODE(MID(A1,ROW(INDIRECT("1:7")),1))))<5,MAX(ABS(77.5-CODE(MID(UPPER(A1)&"A",ROW(INDIRECT("8:9")),1))))<13,ABS(8.5-LEN(A1))=0.5)Abc
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,184
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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