VBA SumIfs with OR criteria

dcuellar

New Member
Joined
Apr 27, 2015
Messages
42
I would like to get a SumIFs function through VBA that uses an array as criteria. This is what I have so far.

Code:
summarySht.range("O15").Value = Application.WorksheetFunction.SumIfs(dataSht.range(janCol & ":" & janCol), _ 
dataSht.range(GetColumnLetter(projectStatusCol) & ":" & GetColumnLetter(projectStatusCol)), projectStatus, _
dataSht.range(GetColumnLetter(programsCol) & ":" & GetColumnLetter(programsCol)), programs, _
dataSht.range(GetColumnLetter(beltDesignationCol) & ":" & GetColumnLetter(beltDesignationCol)), beltDesignation, _
dataSht.range(GetColumnLetter(benefitTypeCol) & ":" & GetColumnLetter(benefitTypeCol)), benefitType)

The variables projectStatus, programs, beltDesignation and benefitType are set up as "Dim projectStatus (0 to 3) As String", for example.

In excel the formula would allow an array within "{}". That will not work in VBA.

Any help with this would be greatly appreciated.
 
Last edited:

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Is the result supposed to be the total of every permutation of the various criteria arrays? (I ask since that wouldn't work as a formula either)
 
Upvote 0
Also, I had it set up originally to filter the different columns and then sum. My question is, will using a sumif function in VBA make the macro run faster than filter and then summing the column?
 
Upvote 0
Is the result supposed to be the total of every permutation of the various criteria arrays? (I ask since that wouldn't work as a formula either)

Yes, if I understand you correctly. So, it would be the equivalent of filtering column A for two criteria, Column B for two criteria and then summing Column C.
 
Last edited:
Upvote 0
It is probably simplest to use nested loops to loop through your three criteria arrays and accumulate the results, but I suspect a filter might be faster.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,610
Messages
6,173,336
Members
452,510
Latest member
RCan29

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