Jyotirmaya
Board Regular
- Joined
- Dec 2, 2015
- Messages
- 205
- Office Version
- 2019
- Platform
- Windows
I have 2 sheets, in sheet1 I have 2 columns Product code and Values, In sheet2 also I have 2 columns Product code and Values, In sheet1 A column a same product may be there for more than one time with different values but in sheet2 the product code is there only for once without having any repetitions.
I want the Sheet1 values should change based on the values of Sheet2
Sheet 1 & Sheet 2
Case 1
I want that in sheet2 when the sum of positive is more than the sum of negative then the negative values total should deduct from Sheet 1 Values, in this case -5 should deduct from Sheet 1 of Product code 2, then it will check the sum of product code 2 from sheet1 in this case its 7(B3)+7(B4)= 14 hence it should deduct 5 hence it can deduct the 5 towards downwards on the column so after deduction of 5 in B3 of sheet1 will be 2 and B4 should be as usual 7.
Similarly in case of product code 4 it should deduct 20 from B6 of sheet1 and the result should be 11 in B6 in Sheet1 after deduction
Case 2
Sheet 2
In the 2nd case if the sum of positive is less than the sum of negative then only I need to deduct that much from product code from Sheet 1. In this case I have sum of positive values is 15 and sum of negative values is 25 then I need to deduct 15 from any product code which has negative values in sheet2, but it should select higher values from the column, so in this case it will select B6 31 value and it should deduct 15 from B6 and the result should be 16 in B6 in sheet1 after deduction
What should be the macro code?
I want the Sheet1 values should change based on the values of Sheet2
Sheet 1 & Sheet 2
Case 1
I want that in sheet2 when the sum of positive is more than the sum of negative then the negative values total should deduct from Sheet 1 Values, in this case -5 should deduct from Sheet 1 of Product code 2, then it will check the sum of product code 2 from sheet1 in this case its 7(B3)+7(B4)= 14 hence it should deduct 5 hence it can deduct the 5 towards downwards on the column so after deduction of 5 in B3 of sheet1 will be 2 and B4 should be as usual 7.
Similarly in case of product code 4 it should deduct 20 from B6 of sheet1 and the result should be 11 in B6 in Sheet1 after deduction
Case 2
Sheet 2
In the 2nd case if the sum of positive is less than the sum of negative then only I need to deduct that much from product code from Sheet 1. In this case I have sum of positive values is 15 and sum of negative values is 25 then I need to deduct 15 from any product code which has negative values in sheet2, but it should select higher values from the column, so in this case it will select B6 31 value and it should deduct 15 from B6 and the result should be 16 in B6 in sheet1 after deduction
What should be the macro code?