Highlight Closest Over/Under Values in Horizontal Range

DixiePiper

New Member
Joined
Oct 19, 2015
Messages
41
Office Version
  1. 365
Platform
  1. Windows
I have searched and searched on this and if there is an answer, I've either not found the magic combination of words to conjure the solution from the depths of the internet or cannot understand my own search result. As such, apologies for any redundancies.

I have a dynamic table in which I want to include some basic data analysis. The number of rows is variable based on data imported via VBA. I have a script to copy the conditional formatting so I only need a solution applicable to a single row.
I need to be able to highlight the closest over/under values to a given number. My table is set up as follows:

ABC
D
E
F
1Ref. ValueLOWMIDHIGH
2$135$111$124$139$157$173

<tbody>
</tbody>

The end result for the above example would be highlighting applied to C2 and D2, representing the closest under (C2) and the closest over (D2).

Caveats and Assumptions:
  • my initial read is I should be able to accomplish this with two separate conditional formatting rules
  • there will be instances where the reference value is outside the parameters of the range; no formatting here is acceptable as I can identify that elsewhere
  • my goal is a visual "at a glance" idea of where the reference value falls on the scale.

Advance thanks for any help.
 
Select C2:G2 and try this CF formula:

=OR(C2=LOOKUP($B2,$C2:$G2),B2=LOOKUP($B2,$C2:$G2))

This highlights both the under and over amounts. It should be robust against changing the location.

And as another thought, if you use a VBA macro to import the data, you may want the same macro to do the highlighting, instead of using CF.
 
Upvote 0

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
First, thank you all for taking time to try and help me. Second, I think things have gotten a bit garbled and for that, my apologies.

I tried to provide a simplified example but maybe it was too simple. Let me try again: (column/row references are actual)
  1. My worksheet has a large table, the size of which is dynamic based on data imported into Column C.
  2. With the exception of two columns, every other column is formula driven based on the values in Column C.
  3. I need to analyze one of the data columns against the metric of survey data. Each row will have a different reference value based on user input and varying metrics based on the value of Column C.
  4. The actual structure of the table is still in flux (adding/deleting columns) but all the reference values are in the same Column and all comparison values are in five consecutive columns.

Maybe this example will work better:
CGMNOPQRS
11CategorySalaryRef. Value(blank)10th
25th50th75th90th
12imported data which drives the formulas in all but Cols G and Col JKeyed data entered by user; Col M is equal to Col G for the purpose of in-cell data analysis using CF data bars based on an INDIRECT formula$135(currently a placeholder)$111$124$139$157$173

<tbody>
</tbody>

The actual content of each row is variable based on the data in Col C. Col M pulls from Col G, Cols O:S are based on INDEX+MATCH formulas that pull data from a separate tab.

I need some way to compare the value of M12 against the range O12:S12 and highlight the closest over/under values. For Row 12, that would be P12:Q12.

Because the size of the table is dynamic based on the contents of Col C, I am using a VBA script to refresh the CF in the "analysis" section. Col M has a data bar workaround that has to be copied to each cell individually and I have a VBA shortcut for that. I will simply link the same copy/paste formatting to Cols O:S.

Again, thank you all for your precious time.
 
Upvote 0
The formula I posted should still work. Select O12:S12 and enter this CF formula:

=OR(O12=LOOKUP($M12,$O12:$S12),N12=LOOKUP($M12,$O12:$S12))

which, come to think of it, can be shortened to:

=OR(LOOKUP($M12,$O12:$S12)=N12:O12)
 
Upvote 0
Eric,
Thank you so much for taking the time to restate your original solution. I got confused and couldn't figure out the references. Thank you for your time and patience.

DixiePiper
 
Upvote 0
Glad it works for you! I probably should have mentioned that the N12 reference intentionally points to the column just before the first column with data. It makes no real sense for the first column, but with relative referencing, it makes the rest of the columns look for the previous value. Without knowing that, it might have been tricky changing the references.

Thanks for the feedback! :)
 
Upvote 0
Thanks. I had to play with the referencing and setup when asking VBA to do the heavy lifting of copying the formatting. Your explanation explains a few of the hiccups I encountered. It works brilliantly and I grateful for your help.

DixiePiper
 
Upvote 0

Forum statistics

Threads
1,215,459
Messages
6,124,947
Members
449,198
Latest member
MhammadishaqKhan

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