MercuryVBA
Board Regular
- Joined
- Nov 12, 2013
- Messages
- 56
Hello,
On the attached data workbook there are two sheets. "Summary" and "Report".
Starting with row 2, column D I've created a multi criteria sum(if()) function that does the following:
On Cell D2 I sum up all the hours on the "Report" sheet where there is a match for B2, C2 and D1 from the "Summary" sheet.
Cell D2 Formula = {=SUM(IF((Report!$B$2:$B$13=Summary!$B2)*(Report!$C$2:$C$13=$C2)*(Report!$D$2:$D$13=D$1),Report!$E$2:$E$13,0))}
I would like to convert this formula to VBA for my macro to perform the calculation without inserting the formula into the cells. The macro should just return the results to the cells.
I tried this in VBA using .Application.WorksheetFunction.SumProduct() - but could not get it to work.
Any help would be much appreciated. Thank you!
"Summary" Sheet
[TABLE="width: 370"]
<colgroup><col><col span="2"><col><col span="2"></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 370"]
<colgroup><col><col span="2"><col><col span="2"></colgroup><tbody>[TR]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD] C
[/TD]
[TD] D
[/TD]
[TD] E
[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name[/TD]
[TD]Serial #[/TD]
[TD]Classificaiton[/TD]
[TD] 8/8/2014
[/TD]
[TD] 8/15/2014
[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]John[/TD]
[TD]12345
[/TD]
[TD] PT
[/TD]
[TD] 10
[/TD]
[TD] 7
[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Jack[/TD]
[TD]23456[/TD]
[TD] FT
[/TD]
[TD] 12
[/TD]
[TD] 8
[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Christie[/TD]
[TD]34567[/TD]
[TD] PT
[/TD]
[TD] 1
[/TD]
[TD] 7
[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Charlie[/TD]
[TD]45678[/TD]
[TD] FT
[/TD]
[TD] 3
[/TD]
[TD] 8
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]
"Report" Sheet
[TABLE="width: 394"]
<colgroup><col><col span="2"><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name[/TD]
[TD]Serial #[/TD]
[TD]Classificaiton[/TD]
[TD]Date[/TD]
[TD]Hrs[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]John[/TD]
[TD]12345[/TD]
[TD]PT[/TD]
[TD]8/8/2014[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Jack[/TD]
[TD]23456[/TD]
[TD]FT[/TD]
[TD]8/8/2014[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Christie[/TD]
[TD]34567[/TD]
[TD]PT[/TD]
[TD]8/8/2014[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Charlie[/TD]
[TD]45678[/TD]
[TD]FT[/TD]
[TD]8/8/2014[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]John[/TD]
[TD]12345[/TD]
[TD]PT[/TD]
[TD]8/8/2014[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Jack[/TD]
[TD]23456[/TD]
[TD]FT[/TD]
[TD]8/8/2014[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Christie[/TD]
[TD]34567[/TD]
[TD]PT[/TD]
[TD]8/15/2014[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]Charlie[/TD]
[TD]45678[/TD]
[TD]FT[/TD]
[TD]8/15/2014[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]John[/TD]
[TD]12345[/TD]
[TD]PT[/TD]
[TD]8/15/2014[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]Jack[/TD]
[TD]23456[/TD]
[TD]FT[/TD]
[TD]8/15/2014[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]Christie[/TD]
[TD]34567[/TD]
[TD]PT[/TD]
[TD]8/15/2014[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]Charlie[/TD]
[TD]45678[/TD]
[TD]FT[/TD]
[TD]8/15/2014[/TD]
[TD]6[/TD]
[/TR]
</tbody>[/TABLE]
On the attached data workbook there are two sheets. "Summary" and "Report".
Starting with row 2, column D I've created a multi criteria sum(if()) function that does the following:
On Cell D2 I sum up all the hours on the "Report" sheet where there is a match for B2, C2 and D1 from the "Summary" sheet.
Cell D2 Formula = {=SUM(IF((Report!$B$2:$B$13=Summary!$B2)*(Report!$C$2:$C$13=$C2)*(Report!$D$2:$D$13=D$1),Report!$E$2:$E$13,0))}
I would like to convert this formula to VBA for my macro to perform the calculation without inserting the formula into the cells. The macro should just return the results to the cells.
I tried this in VBA using .Application.WorksheetFunction.SumProduct() - but could not get it to work.
Any help would be much appreciated. Thank you!
"Summary" Sheet
[TABLE="width: 370"]
<colgroup><col><col span="2"><col><col span="2"></colgroup><tbody>[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
[TR]
[TD][TABLE="width: 370"]
<colgroup><col><col span="2"><col><col span="2"></colgroup><tbody>[TR]
[TD][/TD]
[TD]A
[/TD]
[TD]B
[/TD]
[TD] C
[/TD]
[TD] D
[/TD]
[TD] E
[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name[/TD]
[TD]Serial #[/TD]
[TD]Classificaiton[/TD]
[TD] 8/8/2014
[/TD]
[TD] 8/15/2014
[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]John[/TD]
[TD]12345
[/TD]
[TD] PT
[/TD]
[TD] 10
[/TD]
[TD] 7
[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Jack[/TD]
[TD]23456[/TD]
[TD] FT
[/TD]
[TD] 12
[/TD]
[TD] 8
[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Christie[/TD]
[TD]34567[/TD]
[TD] PT
[/TD]
[TD] 1
[/TD]
[TD] 7
[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Charlie[/TD]
[TD]45678[/TD]
[TD] FT
[/TD]
[TD] 3
[/TD]
[TD] 8
[/TD]
[/TR]
</tbody>[/TABLE]
[/TD]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD][/TD]
[TD="align: right"][/TD]
[TD="align: right"][/TD]
[/TR]
</tbody>[/TABLE]
"Report" Sheet
[TABLE="width: 394"]
<colgroup><col><col span="2"><col><col><col></colgroup><tbody>[TR]
[TD][/TD]
[TD]A[/TD]
[TD]B[/TD]
[TD]C[/TD]
[TD]D[/TD]
[TD]E[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Name[/TD]
[TD]Serial #[/TD]
[TD]Classificaiton[/TD]
[TD]Date[/TD]
[TD]Hrs[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]John[/TD]
[TD]12345[/TD]
[TD]PT[/TD]
[TD]8/8/2014[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD]Jack[/TD]
[TD]23456[/TD]
[TD]FT[/TD]
[TD]8/8/2014[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]Christie[/TD]
[TD]34567[/TD]
[TD]PT[/TD]
[TD]8/8/2014[/TD]
[TD]1[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]Charlie[/TD]
[TD]45678[/TD]
[TD]FT[/TD]
[TD]8/8/2014[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]6[/TD]
[TD]John[/TD]
[TD]12345[/TD]
[TD]PT[/TD]
[TD]8/8/2014[/TD]
[TD]6[/TD]
[/TR]
[TR]
[TD]7[/TD]
[TD]Jack[/TD]
[TD]23456[/TD]
[TD]FT[/TD]
[TD]8/8/2014[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]8[/TD]
[TD]Christie[/TD]
[TD]34567[/TD]
[TD]PT[/TD]
[TD]8/15/2014[/TD]
[TD]4[/TD]
[/TR]
[TR]
[TD]9[/TD]
[TD]Charlie[/TD]
[TD]45678[/TD]
[TD]FT[/TD]
[TD]8/15/2014[/TD]
[TD]2[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]John[/TD]
[TD]12345[/TD]
[TD]PT[/TD]
[TD]8/15/2014[/TD]
[TD]7[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]Jack[/TD]
[TD]23456[/TD]
[TD]FT[/TD]
[TD]8/15/2014[/TD]
[TD]8[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]Christie[/TD]
[TD]34567[/TD]
[TD]PT[/TD]
[TD]8/15/2014[/TD]
[TD]3[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]Charlie[/TD]
[TD]45678[/TD]
[TD]FT[/TD]
[TD]8/15/2014[/TD]
[TD]6[/TD]
[/TR]
</tbody>[/TABLE]
Last edited: