Highlight rows till the sum is close to X Value

asolopreneur

New Member
Joined
Nov 15, 2017
Messages
40
Platform
  1. Windows
1638199189750.png
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You need to clearly define what qualifies as "close to"?
Exactly how close does it need to be?
 
Upvote 0
Is this for Excel, or Google Sheets?
 
Upvote 0
I can only assume that you mean the "highest value that is still less than or equal to the value you are looking for", i.e. 510 is still less than 535, but 540 is not (hence the value that adds up to 510 is the last value you want).

However, I do not use Google Sheets at all, so I have no idea if Conditional Formatting works the same in Google Sheets as it does in Excel.
If it does work the same, you would just select cells F2 down to the end of the data in column F, and enter the following Conditional Formatting formula:
Excel Formula:
=SUM(F$2:F2)<=G$2
and select your yellow fill option.

If it does not work the same way in Google Sheet, I will need to "punt" on this one...
 
Upvote 0
Solution
Perfect!

Can you please explain why G$2 and not G2 or $G2 or $G$2? (Just to improve my Excel sheet skill)
 
Upvote 0
Using a "$" in front of the column or row reference makes it an "absolute" reference, which "locks it down", so that it doesn't float as you move down the column.

So, since our first formula is applied to cell F2, then F3 (and all other cells in column F) would then also look at G2.
If we did not have the "$" there, F3 would look at G3 instead of G2.

See here for more details: Switch between relative, absolute, and mixed references
 
Upvote 0

Forum statistics

Threads
1,215,772
Messages
6,126,814
Members
449,340
Latest member
hpm23

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