Conditional formatting when comparing strings

markh9999

New Member
Joined
Aug 21, 2007
Messages
49
I want to shade a cell if its contents are 'less than' another cell. The problem is the two cells are alphanumeric. Here's an example.

The cell can contain 7a, 7b, 7c, 6a, 6b or 6c and the cell to comapre it against will contain one of these as well. But I want to shade if the cell is "less than" the other one. Less than here means that 6c is less than 6b, 6b is less than 6a and 6a is less than 7c etc (in other words the order I have shown them above is highest to lowest).

How can I do this in a single conditional statement without having to introduce new fields to assign a numeric value to compare with.

Hope this makes sense.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
If the 2 cells are A1 and B1 then you can use the following formula in the conditional formatting:
=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE($B1,"a",3),"b",2),"c",1)<
SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(A$1,"a",3),"b",2),"c",1)<substitute(substitute(substitute(a$1,"a",3),"b",2),"c",1)[ code]<substitute(substitute(substitute(a$1,"a",3),"b",2),"c",1)[="" code]<substitute(substitute(substitute(a$1,"a",3),"b",2),"c",1)<substitute(substitute(substitute(a$1,"a",3),"b",2),"c",1)<="" html=""></substitute(substitute(substitute(a$1,"a",3),"b",2),"c",1)[>
 
Last edited:
Upvote 0
And also a bit shorter:
=LEFT($B1,1)+CODE(RIGHT($B1,1))/1000<<left($a1,1)+code(right($a1,1)) 1000[="" code]

<left($a1,1)+code(right($a1,1)) 1000
LEFT($A1,1)+CODE(RIGHT($A1,1))/1000<left($a1,1)+code(right($a1,1)) 1000<left(a1,1)+code(right(a1,1))="" 1000<left($a1,1)+code(right($a1,1))="" 1000<="" html=""></left($a1,1)+code(right($a1,1))></left($a1,1)+code(right($a1,1))></left($a1,1)+code(right($a1,1))>
 
Last edited:
Upvote 0
I want to shade a cell if its contents are 'less than' another cell. The problem is the two cells are alphanumeric. Here's an example.

The cell can contain 7a, 7b, 7c, 6a, 6b or 6c and the cell to comapre it against will contain one of these as well. But I want to shade if the cell is "less than" the other one. Less than here means that 6c is less than 6b, 6b is less than 6a and 6a is less than 7c etc (in other words the order I have shown them above is highest to lowest).

How can I do this in a single conditional statement without having to introduce new fields to assign a numeric value to compare with.

Hope this makes sense.
Let's assume you want to format cell A1 if it contains one of those entries and it is less than one of those entries in cell B1.

Conditional Formatting
Use the "Formula option".

Use this formula:

=AND(A1<>"",A1 < B1)<B1)< html>
 
Upvote 0

Forum statistics

Threads
1,213,484
Messages
6,113,927
Members
448,533
Latest member
thietbibeboiwasaco

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