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
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
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

How much near to the value of J1?
I mean there is only 1 reference we are getting for each row.
i.e 8 is nearest to 7.
but 22 is also nearest to 1 (If there is no other value to compare !!!)

so, is there any definition of "Nearest" ? I mean +/- 3 or something like that?




on upper side or Lower side?

Nearest on greater side , or lesser side or just nearest?
 
Upvote 0
Thank you for your reply - I hope this explains it better.

In the example above I enter a value manually in J1- in this example it was 17.

The values in H4:H13 are entered manually
then when data is entered elsewhere in the spreadsheet the values in J4:J13 will increase.
When a value in a cell in J4:J13 reaches 7 I require the cell/s in the same row in Column H to be highlighted

The problem bit is when more than one cell in J4:J13 reaches 7 then I require the cell/s in the same row in column H to be highlighted that has a value nearest to the value in J1 (17) (upside and downside)
In this example J4 ,J5 and J7 have reached 7 but only the cells H5 (8) and H7 (8) are highlighted because the values in them are closer to the value in J1 (17) than the value in J4 (7) -- {because 8 is closer to 17 than 7}


If the value in J1 had been 3 then H4 would have been highlighted as the value in H4 (7) is closer to the value in J1 (3) than the values in H5 (8) and H7 (8)

Does that make sense

Thanks again for your time
 
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
117
2
3
4Red77
5Black87
6Blue173
7Green87
8White496
9Brown52
10Grey315
11Scarlet116
12Yellow135
13Orange221
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
 
Upvote 0
Use this formula in both the columns H and B for conditional formatting.

=MIN(IF($J$4:$J$13=7,ABS($J$1-$H$4:$H$13)))=ABS($J$1-$H4)
 
Upvote 0
Conditional formatting
CellNr.: / ConditionFormat
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

<tbody>
</tbody>

<tbody>
</tbody>


Excel tables to the web >> Excel Jeanie HTML 4

Sir,
Can't we avoid AND function?

Because MIN(IF will take care of the essential condition J4=7 by excluding other values from comparison...
 
Upvote 0
Select H4:H13 and run the following formula in CF...

=$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))

Select B4:B13 and run the same formula.
 
Upvote 0
Sir,
Can't we avoid AND function?

Because MIN(IF will take care of the essential condition J4=7 by excluding other values from comparison...
No.

With the sample data as shown in my sheet, but with your CF formulas in place, change any of the other cells in column H to 8
 
Upvote 0
Select H4:H13 and run the following formula in CF...

=$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))
Aladin, that does not address the highlighted condition below

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
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,755
Members
448,989
Latest member
mariah3

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