Conditional formatting formula - multi criteria please

Orangeanorak

Active Member
Joined
Nov 22, 2002
Messages
276
Office Version
  1. 365
Platform
  1. Windows
conditional formatting?

I posted something similar to this some time ago but never got an answer and it 'fell off' the board. Here's hoping for a solution this time please.

1. Formula please to highlight the cell in column H that is equal to or nearest to J1 IF the cell in the same row in column J equals 7


2. Formula to highlight the cell in column B if the cell on the same row in column H is highlighted as a result of the above.
Excel Workbook
ABCDEFGHIJ
1*********17
2**********
3**********
41Red*****7*7
52Black*****8*7
63Blue*****17*3
74Green*****8*7
85White*****49*6
96Brown*****5*2
107Grey*****31*5
118Scarlet*****11*6
129Yellow*****13*5
1310Orange*****22*1
Sheet


Thank you - your help is appreciated
 
Aladin, that does not address the highlighted condition below

An oversight. Thanks for pointing that out. Adding thet condition, we get

=AND($J4=7,$H4=INDEX($H$4:$H$13,MATCH(MIN(ABS(IF($J$4:$J$13=7,$H$4:$H$13)-$J$1)),ABS(IF($J$4:$J$13=7,$H$4:$H$13-$J$1)),0)))
 
Upvote 0

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Try this.
1. Select B4:B10 and H4:H10, ensuring either B4 or H4 is the active cell.
2. Apply the CF shown.

Excel Workbook
BCDEFGHIJ
1********17
2*********
3*********
4Red*****7*7
5Black*****8*7
6Blue*****17*3
7Green*****8*7
8White*****49*6
9Brown*****5*2
10Grey*****31*5
11Scarlet*****11*6
12Yellow*****13*5
13Orange*****22*1
14*********
CF Nearest with Condition
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B41. / Formula is =AND($J4=7,ABS($J$1-$H4)=MIN(IF($J$4:$J$13=7,ABS($H$4:$H$13-$J$1))))Abc

Thank you Peter SS this works perfectly

Aladin - Thank you for your formula - it covered everything except in situations where a cell in H4:H13 does not match J1 exactly the HIGHER AND LOWER nearest numbers to the J1 number did not both show the formatting.
 
Upvote 0
Upvote 0
I believe what the OP is saying is that in the sample, if H5 was changed to 26, both H5 and H7 should be highlighted because they are both 9 away from J1.

Thats it. Thank you for explaining this more clearly
 
Upvote 0
And a final one on this please
Can you give me the formula to count the number of cells in column H that fit this criteria i.e. the ones that turn orange
In this example H5 and H7 - total 2
 
Upvote 0
Type/Copy this formula

=SUMPRODUCT(--($J$4:$J$13=7),--(ABS($J$1-$H4:$H13)=MIN(IF($J$4:$J$13=7,ABS($H$4:$H$13-$J$1)))))

Press Ctrl+Shift+Enter, not just Enter
 
Upvote 0
.. or for a normal-entry formula, if you are using Excel 2010 or later:

=SUMPRODUCT(--(J4:J13=7),--(ABS(J1-H4:H13)=AGGREGATE(15,6,ABS(J1-H4:H13)/(J4:J13=7),1)))
 
Upvote 0
Try this.
1. Select B4:B10 and H4:H10, ensuring either B4 or H4 is the active cell.
2. Apply the CF shown.

Excel Workbook
BCDEFGHIJ
1********17
2*********
3*********
4Red*****7*7
5Black*****8*7
6Blue*****17*3
7Green*****8*7
8White*****49*6
9Brown*****5*2
10Grey*****31*5
11Scarlet*****11*6
12Yellow*****13*5
13Orange*****22*1
14*********
CF Nearest with Condition
Cells with Conditional Formatting
CellConditionCell FormatStop If True
B41. / Formula is =AND($J4=7,ABS($J$1-$H4)=MIN(IF($J$4:$J$13=7,ABS($H$4:$H$13-$J$1))))Abc

Sorry people - one more tweak if possible please
I need this CF to work when J1 is greater than zero

Thanks
 
Upvote 0
I need this CF to work when J1 is greater than zero
Try..
=AND($J$1>0,$J4=7,ABS($J$1-$H4)=MIN(IF($J$4:$J$13=7,ABS($H$4:$H$13-$J$1))))


BTW, best not to quote whole longish posts as the default - it makes the thread harder to read/navigate and just occupies storage space needlessly. If you want to quote, quote small, relevant parts only.
 
Upvote 0

Forum statistics

Threads
1,216,082
Messages
6,128,716
Members
449,464
Latest member
againofsoul

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