VBA SUMIF with multiple criteria

ExcelEveryday1

New Member
Joined
Jan 7, 2016
Messages
20
Good Morning! I have written a sumif sub that summarizes "value" based off of the criteria in the three columns to the left.

YearContract typePrice RangeValue
Year1ATwenty >19
Year2BFourty +45
Year2CTwenty >15
Year2DFourty +50

<tbody>
</tbody><colgroup><col><col span="3"></colgroup>


Unfortunately, 2 years, with 4 contract types and 2 price ranges leaves me with 16 combinations of variables to sumif, and I will probably have to do this with more variables in the future. I have sumIfed the total as seen below for all 16 combinations using 4 "for to" loops

For x = FirstRow To LastRow
If Cells(x, 2) = Cells(3, 6) And Cells(x, 3) = Cells(2, 7) And Cells(x, 4) = Cells(2, 8) Then
Ce = 1 + Ce
ElseIf Cells(x, 2) = Cells(3, 6) And Cells(x, 3) = Cells(3, 7) And Cells(x, 4) = Cells(2, 8) Then
Cf = 1 + Cf
ElseIf Cells(x, 2) = Cells(3, 6) And Cells(x, 3) = Cells(4, 7) And Cells(x, 4) = Cells(2, 8) Then
Cg = 1 + Cg
ElseIf Cells(x, 2) = Cells(3, 6) And Cells(x, 3) = Cells(5, 7) And Cells(x, 4) = Cells(2, 8) Then
Ch = 1 + Ch
End If
Next x


etc....


There's got to be a simpler way to do this. Any ideas?
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Which version of Excel are you using?
In XL2007+, we have the SUMIFS function, perfectly suited for that task.
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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