SUMIFS in VBA

TG2812

Board Regular
Joined
Apr 15, 2015
Messages
192
Hi, can anyone explain me how to translate this formula excel into VBA?

=SUMIFS($H:$H,$A:$A,$A2,$B:$B,$B2,$D:$D,$D2,$E:$E,$E2)

Thanks in advance for your help.
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Re: SUMIFS in VBA Help needed please

Hi TG2812,

This will put the value of the formula to a variable called dblMyVal:

Code:
Option Explicit
Sub Macro1()

    Dim dblMyVal As Double
    
    dblMyVal = WorksheetFunction.SumIfs(Range("$H:$H"), Range("$A:$A"), Range("$A2"), Range("$B:$B"), Range("$B2"), Range("$D:$D"), Range("$D2"), Range("$E:$E"), Range("$E2"))
    
    MsgBox dblMyVal

End Sub

HTH

Robert
 
Upvote 0
Re: SUMIFS in VBA Help needed please

Thank you Robert. Works like a charm. Just a small adjustment.

I have date in column E. How can I ensure the formula sums up data from the same month and year?
 
Upvote 0
Re: SUMIFS in VBA Help needed please

Along with your other criteria, this will sum all the dates in Col. E within the range 1-Dec-2018 to 31-Dec-2018:

=SUMIFS($H:$H,$A:$A,$A2,$B:$B,$B2,$D:$D,$D2,$E:$E,">=2018/12/1",$E:$E,"<=2018/12/31")

HTH

Robert
 
Last edited:
Upvote 0
Re: SUMIFS in VBA Help needed please

Hi,

It still does not work:

dblMyVal = WorksheetFunction.SumIfs(Range("$H:$H"), Range("$A:$A"), Range("$A2"), Range("$B:$B"), Range("$B2"), Range("$D:$D"), Range("$D2"), Month(Range("$E:$E")), "=" & Month(Range("$E2")))
 
Upvote 0
Re: SUMIFS in VBA Help needed please

I'm not sure if you can do a SUMIF on month like that :( Someone on the forum will a better idea I'm sure :)
 
Last edited:
Upvote 0
Re: SUMIFS in VBA Help needed please

Does anyone have an idea on how to solve the matter? Thank you in advance for the support.
 
Upvote 0
Re: SUMIFS in VBA Help needed please

Thanks for the info! Any idea how to do it in VBA?
Using the same methods that have already been discussed in this thread (using Worksheetfunction).
It should be the exact same process, just using a different function.
The other thread shows how how to structure the SUMPRODUCT function to work for months.
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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