Excel Macro help if Red cell values are there then compensate that value with Black cell values

Jyotirmaya

Board Regular
Joined
Dec 2, 2015
Messages
205
Office Version
  1. 2019
Platform
  1. Windows
I have two sheets, Sheet1 and Sheet2, There are 3 categories in my sheet A category, B category, C category. Under each category there are 5 sub categories and they are 1st year, 2nd year, 3rd year, 4th year, 5th year. In a column for example I have some values and I have the sum of the values if in a column there are values in Red then that will be consider as Excess amount collected values and that I need to compensate against the same column values in same category. For example in my example I have 35 in excess in SL row column A 103 and I need to compensate that 35 among 100,101,103,104 SL row hence it should start from lesser values such as It will first choose value 4 of B7 to compensate then value 5 of B6 then value 10 of B3 then the Value 20 of B4 but the Black sum amount is 39 of B column and excess amount is 35 so it can compensate only 35, so after compensating 4+5+10 it will compensate 16 from from B4.


Similarly in a column if there are excess values more than 1 then it will start compensating from the highest amount such as in my example there two excess amount in Column C in 2nd year there are two Excess amount 20 and 50 in Sl row 101 and 102, but the Black sum is 19 and excess sum is 70 so 50 is compensated and rest excess balance amount is there 31 after compensating.


What should be the code to make this in sheet2 from Column B to column P, I have 2000 rows so the TOTAL in Black and Red is there in A2001 & A2002 and the sum in Black and Red are already there.


sheet%2B1.JPG

Sheet1

sheet%2B2.JPG


Sheet 2
 
Last edited:

Excel Facts

How to create a cell-sized chart?
Tiny charts, called Sparklines, were added to Excel 2010. Look for Sparklines on the Insert tab.

Forum statistics

Threads
1,223,881
Messages
6,175,159
Members
452,615
Latest member
bogeys2birdies

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