SUMIFS in VBA

Zzz999

New Member
Joined
Jul 1, 2015
Messages
24
Hello. I need help in figuring out on the project I've been working on lately. In excel, I know how to use SUMIFS. I know it's possible to make it work in VBA but I really had no idea how. As I would like to use the formula instead, I really need to do it in macro, because the sheet gets updated every month. This is the formula:
Code:
 =SUMIFS(N5:N286,A5:A286,"*Team*", A5:A286, "*Total*")

I above code works if done manually, but it's not really okay because the range is specific and it only ends in 286. I want it to search to the last row of the sheet

I have a sheet (Budget) that gets updated every month. It should find the words "Team" and "Total" in column A and sum up those Amount in column N (same row), and find the words "Grand Total" in column A and its sum will be placed on column N.
Here's the sample table below:

TeamPurchaserAmount
Team AJen125
Jen458
Jen569
Team A Total1152
Team BFrank895
Frank654
Frank774
Frank845
Frank221
Team B Total3389
Team CMike415
Mike784
Team C Total1199
Grand Total0

<tbody>
</tbody>

So the grand total should be 5740 and it will be placed in column N.

Any suggestions will be greatly appreciated. Thank you!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Just reference the entire columns. The function will automatically calculate the used range of the worksheet. It doesn't sum the empty rows beyond your last used row.

=SUMIFS(N:N, A:A,"*Team*", A:A, "*Total*")

Also, I think you could combine the two criteria like this...
=SUMIFS(N:N, A:A,"*Team*Total*")
 
Last edited:
Upvote 0
Just reference the entire columns. The function will automatically calculate the used range of the worksheet. It doesn't sum the empty rows beyond your last used row.

=SUMIFS(N:N, A:A,"*Team*", A:A, "*Total*")

Also, I think you could combine the two criteria like this...
=SUMIFS(N:N, A:A,"*Team*Total*")

I've also thought about that. But I need to find the "Grand Total" and automatically place the sum on its row in column N
 
Upvote 0
Code:
[color=darkblue]Sub[/color] Grand_Total()
    [color=darkblue]Dim[/color] GT [color=darkblue]As[/color] Range
    [color=darkblue]Set[/color] GT = Range("A:A").Find("Grand Total", , , xlWhole, , , [color=darkblue]False[/color])
    [color=darkblue]If[/color] [color=darkblue]Not[/color] GT [color=darkblue]Is[/color] [color=darkblue]Nothing[/color] [color=darkblue]Then[/color]
        Cells(GT.Row, "N").FormulaR1C1 = "=SUMIF(R5C1:R[-1]C1, ""*Team*Total*"", R5C:R[-1]C)"
    [color=darkblue]Else[/color]
        MsgBox "'Grand Total not found in column A. ", vbExclamation, "Grand Taotal Not Found"
    [color=darkblue]End[/color] [color=darkblue]If[/color]
End [color=darkblue]Sub[/color]
 
Upvote 0

Forum statistics

Threads
1,216,089
Messages
6,128,750
Members
449,466
Latest member
Peter Juhnke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top