Conditional Formatting Based on 2 Criteria

L

Legacy 143009

Guest
I am quite weak at conditional formatting.
What should I do to paint column B cell values in red if column A value equals to matches any value in column C and the adjacent D value is smaller than column C value?

Column AColumn BColumn CColumn D
Cat25Cat23
Bird4Dog10
Bird5
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
i used to hate conditional formatting, then i realised i could work out the needed formula in a cell, which is a much more user friendly interface, and then just paste it in.

Excel Formula:
=IFERROR(XLOOKUP(@A:A,C:C,D:D)<@B:B,FALSE)

uses an xlookup to return the column D value based on column A, then compares it to B. if its not found it will N/A error, which will result in a false return.
 
Upvote 0
i used to hate conditional formatting, then i realised i could work out the needed formula in a cell, which is a much more user friendly interface, and then just paste it in.

Excel Formula:
=IFERROR(XLOOKUP(@A:A,C:C,D:D)<@B:B,FALSE)

uses an xlookup to return the column D value based on column A, then compares it to B. if its not found it will N/A error, which will result in a false return.
Thanks for your reply!
I think my Excel version does not support XLOOKUP :( Also what does "@" sign mean? I've never used it before.
 
Upvote 0
i'd miss the functionality of 2016+ if i lost it now! the @ sign is structured reference to mean "in this row".
We can bypass the xlookup using vlookup. xlookup is simply a replacement in more recent excel versions.

Excel Formula:
=IFERROR(VLOOKUP(A1,C:D,2,FALSE)<B1,FALSE)

if you apply that to the entire B column it should work in your version. its important that the A1 and B1 references are the first cell the conditional formatting is applied to.
 
Upvote 0
Solution
Is it certain that the values in column C will never appear more than once in column C? That is, can we be sure that columns C:D would never be like this?

22 11 04.xlsm
CD
1Cat28
2Dog10
3Bird5
4Cat15
CF (2)


If the answer is that the column C values are unique, then a simpler version (no need for the IFERROR) of the suggested formula should also work for you

22 11 04.xlsm
ABCD
1Cat25Cat23
2Bird4Dog10
3Rat5Bird5
CF
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B1:B3Expression=VLOOKUP(A1,C:D,2,FALSE)<B1textNO


If it is possible that values can repeat in column C then a different formula would be required. One such would be this

22 11 04.xlsm
ABCD
1Cat25Cat28
2Bird4Dog10
3Bird5
4Cat15
CF (2)
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B1:B2Expression=COUNTIFS(C$1:C$9,A1,D$1:D$9,"<"&B1)textNO
 
Upvote 0
Yes, column C is a unique list. Yes, I stripped IFERROR function. Thanks for the reminder anyway :)
I am good at formulas but I always have confusions while I build up a condition. I am never certain when to choose a range and when to choose a value. Sometimes I select a range to apply and Conditional Formmatting is givin an error something like "Can not select a range" or something similar. I know functions, I know arrays, I know VBA but never understand Conditional Formatting :)
 
Upvote 0

Forum statistics

Threads
1,215,942
Messages
6,127,807
Members
449,408
Latest member
Bharathi V

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