PDA

View Full Version : sum the numbers under criteria



Yjmmay34
08-12-2010, 10:16 PM
Hi, all . I need help with this problem. I want to sum the Qty if the Geo, Year, and Mon are same. then it should only the sum quantity left in the worksheet. Just like the sample i attached, please refer to it, which will be easier to understand.
Thank you!

geekgirlau
08-12-2010, 10:33 PM
=SUMPRODUCT(($D$3:$D$22=M3)*($E$3:$E$22=N3)*($F$3:$F$22=O3)*$G$3:$G$22)

Yjmmay34
08-12-2010, 11:38 PM
Hi, geek. i need a macro code to run this result. Because i need to insert this macro to my whole macro program. Please help. Thank you!

geekgirlau
08-15-2010, 04:41 PM
That's the formula that will calculate the result you want, but you haven't explained what you're attempting to do. Does the sample represent the structure of the file? How will the macro be triggered? What cells need to be updated? If the formula exists, why do you need a macro?

Please post the code you have so far.

Yjmmay34
08-15-2010, 05:39 PM
Hi, geek. Thank you for youe attention. I just need a macro to sum the number based on the condition. after sum those number, there is another macro to extract the sum number.

geekgirlau
08-15-2010, 07:46 PM
Where are your criteria ranges going to be? These are currently in columns M, N & O in your sample.
Will these be static, or do you need to calculate these from your data range?

Yjmmay34
08-15-2010, 08:25 PM
yes, geek. it will the static. i want to sum the number under same Geo, year, and month. then the sum number overwrite original data.

geekgirlau
08-15-2010, 08:35 PM
Assuming you have named ranges:


Sheets("MySheet").Range("ResultRange").FormulaR1C1 = _
"=SUMPRODUCT((YearRange=RC[-3])*(QtrRange=RC[-2])*(MonthRange=RC[-1])*QtyRange)