technowerk
New Member
- Joined
- Oct 30, 2012
- Messages
- 5
Hi,
Following is a sample data I have. I have written a macro that does various calculations for me. However, now I'm stuck on coding SumProduct function.
[TABLE="width: 320"]
<tbody>[TR]
[TD="class: xl63, width: 64"]Company[/TD]
[TD="class: xl63, width: 64"]Employee[/TD]
[TD="class: xl63, width: 64"]Emp_grade[/TD]
[TD="class: xl63, width: 64"]Year[/TD]
[TD="class: xl63, width: 64"]Salary[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2000[/TD]
[TD="class: xl63, align: right"]2500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]B[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]1997[/TD]
[TD="class: xl63, align: right"]4000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2002[/TD]
[TD="class: xl63, align: right"]2750[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]C[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]1998[/TD]
[TD="class: xl63, align: right"]5500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]D[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]1998[/TD]
[TD="class: xl63, align: right"]1500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2003[/TD]
[TD="class: xl63, align: right"]3000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2004[/TD]
[TD="class: xl63, align: right"]3500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]E[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2000[/TD]
[TD="class: xl63, align: right"]6000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2005[/TD]
[TD="class: xl63, align: right"]3750[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2005[/TD]
[TD="class: xl63, align: right"]4500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]F[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2001[/TD]
[TD="class: xl63, align: right"]4000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]D[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2001[/TD]
[TD="class: xl63, align: right"]6000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]G[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2001[/TD]
[TD="class: xl63, align: right"]7500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2008[/TD]
[TD="class: xl63, align: right"]5500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]B[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2000[/TD]
[TD="class: xl63, align: right"]2500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]F[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]1990[/TD]
[TD="class: xl63, align: right"]1500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]H[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2004[/TD]
[TD="class: xl63, align: right"]5000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]I[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2010[/TD]
[TD="class: xl63, align: right"]7000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]J[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2000[/TD]
[TD="class: xl63, align: right"]3000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]4[/TD]
[TD="class: xl63"]F[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2008[/TD]
[TD="class: xl63, align: right"]5500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]4[/TD]
[TD="class: xl63"]K[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2009[/TD]
[TD="class: xl63, align: right"]6000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]4[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2009[/TD]
[TD="class: xl63, align: right"]5750[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2010[/TD]
[TD="class: xl63, align: right"]6000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2011[/TD]
[TD="class: xl63, align: right"]7500[/TD]
[/TR]
</tbody>[/TABLE]
This data is filtered data (I have applied advanced filter to get this data). Now I would like to sum 'Salary' when Employee=A AND Emp_grade=3.
As SUMIF works ONLY for 1 condition, I had to opt for SumProduct.
Here's what I've coded
This gives an error. I tried recording a macro and using the same code in my code but it doesn't work either. Can someone help please?
I do not want to use pivot table as the actual data is too large to fit on a single sheet of pivot table (about 95 columns and over 12000 rows) and thus there's a risk of losing data if I create a pivot table.
Is there any other function that I can use instead of SumProduct to combine 2 or more conditions in the same statement?
Thanks in advance!
Following is a sample data I have. I have written a macro that does various calculations for me. However, now I'm stuck on coding SumProduct function.
[TABLE="width: 320"]
<tbody>[TR]
[TD="class: xl63, width: 64"]Company[/TD]
[TD="class: xl63, width: 64"]Employee[/TD]
[TD="class: xl63, width: 64"]Emp_grade[/TD]
[TD="class: xl63, width: 64"]Year[/TD]
[TD="class: xl63, width: 64"]Salary[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2000[/TD]
[TD="class: xl63, align: right"]2500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]B[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]1997[/TD]
[TD="class: xl63, align: right"]4000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2002[/TD]
[TD="class: xl63, align: right"]2750[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]C[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]1998[/TD]
[TD="class: xl63, align: right"]5500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]D[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]1998[/TD]
[TD="class: xl63, align: right"]1500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2003[/TD]
[TD="class: xl63, align: right"]3000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2004[/TD]
[TD="class: xl63, align: right"]3500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]E[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2000[/TD]
[TD="class: xl63, align: right"]6000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2005[/TD]
[TD="class: xl63, align: right"]3750[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2005[/TD]
[TD="class: xl63, align: right"]4500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]F[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2001[/TD]
[TD="class: xl63, align: right"]4000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]D[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2001[/TD]
[TD="class: xl63, align: right"]6000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]G[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2001[/TD]
[TD="class: xl63, align: right"]7500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2008[/TD]
[TD="class: xl63, align: right"]5500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]B[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2000[/TD]
[TD="class: xl63, align: right"]2500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]F[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]1990[/TD]
[TD="class: xl63, align: right"]1500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]H[/TD]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63, align: right"]2004[/TD]
[TD="class: xl63, align: right"]5000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]I[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2010[/TD]
[TD="class: xl63, align: right"]7000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63"]J[/TD]
[TD="class: xl63, align: right"]3[/TD]
[TD="class: xl63, align: right"]2000[/TD]
[TD="class: xl63, align: right"]3000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]4[/TD]
[TD="class: xl63"]F[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2008[/TD]
[TD="class: xl63, align: right"]5500[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]4[/TD]
[TD="class: xl63"]K[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2009[/TD]
[TD="class: xl63, align: right"]6000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]4[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2009[/TD]
[TD="class: xl63, align: right"]5750[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2010[/TD]
[TD="class: xl63, align: right"]6000[/TD]
[/TR]
[TR]
[TD="class: xl63, align: right"]2[/TD]
[TD="class: xl63"]A[/TD]
[TD="class: xl63, align: right"]1[/TD]
[TD="class: xl63, align: right"]2011[/TD]
[TD="class: xl63, align: right"]7500[/TD]
[/TR]
</tbody>[/TABLE]
This data is filtered data (I have applied advanced filter to get this data). Now I would like to sum 'Salary' when Employee=A AND Emp_grade=3.
As SUMIF works ONLY for 1 condition, I had to opt for SumProduct.
Here's what I've coded
Code:
Dim TOT_SUM As Double
TOT_SUM=Application.WorksheetFunctions.SumProduct((B2:B65535="A"),(C2:C65535=3),E2:E65535)
This gives an error. I tried recording a macro and using the same code in my code but it doesn't work either. Can someone help please?
I do not want to use pivot table as the actual data is too large to fit on a single sheet of pivot table (about 95 columns and over 12000 rows) and thus there's a risk of losing data if I create a pivot table.
Is there any other function that I can use instead of SumProduct to combine 2 or more conditions in the same statement?
Thanks in advance!
Last edited: