Missing In above O3=2
Hi,What will be the vba code for generation of data from I5:S17 which I have highlighted with yellow.
I am trying to get data by matching vertical column A & Column B (Criteria1 & 2 ) with horizontal row 2 & 3 (Criteria 1 & 2) with breakdown of Criteria 3 i.e Column D in the way presented in column I,K,M,O,Q,S and so on.
The test sub below assumed that the things I asked in my comment will never happen. Also it assumed that column A and column C row value is sorted.
It create a range variable from i2 to whatever last column row 2 with value as rg, then it loop to each cell which has value in rg.
Then it create rgP variable as the range in column A which has value of the looped cell value. Then it check if the looped cell offset 1,0 value is blank then create rgQ range from rgP offset 0,1 (column B) which value is the looped cell offset 1,0, else it set rgQ from rgP offset 0,3.
Now we have a range of qty as rgQ which coming from the looped cell.value and its offset(1,0) value as the vertical criteria which compared with the horizonal criteria (the rows) of column A and column B.
Then it take the value of the looped cell offset 2,0 as qty1
create a zero value as qty2 for a sum comparison
and set a range as qty from the last cell of rgQ.
then it do a sum checking by looping.
In the Do-Loop:
A. as long as the qty cell is not the first cell of rgP:
then it do the calculation as seen in the code.
B. soon the qty cell is the the first cell of rgP, then it's the last thing to do a calculation to compare, which either the result is negative or positive.
(I'm sorry I can't describe it well as it's too difficult for me to explain in English).
Please note, the sub doesn't check whether the looped cell exist in column A or not, and also it doesn't check whether the looped cell.offset(1,0) value exist in rgP.Offset(0, 1) (column B).