VBA SumIfs with Dates for comparison

jscambray

New Member
Joined
Dec 13, 2018
Messages
7
Hi,

I am in need of some help using SumIfs with VBA when dates are involved. Basically the variable goLiveDate is 5/1/2018 read in from cell A1 on a worksheet. dataSheet.Range("G:G") contains a range of different dates on a worksheet formatted as short date. I have tried CLng and CDate and answer still produces 0 when date comparison is added to the SumIfs. Any help appreciated.

Code:
For i = 9 To dashboardMetricsSheetLastRow
      
collectionTotal = Application.WorksheetFunction.SumIfs(dataSheet.Range("D:D"), dataSheet.Range("G:G"), "<" & Clng(goLiveDate), dataSheet.Range("H:H"), "=" & marketName, dataSheet.Range("B:B"), "=" & dashboardMetricsSheet.Range("A" & i))


Next

Thanks,

Justin
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi,

Before jumping into VBA ... have you tested your formula in your spreadsheet ?
 
Upvote 0
It does not. I still get 0. I guess I am not understanding how to make Date comparisons using SumIfs in excel. Here is the excel forumla.

=SUMIFS(Data!$D:$D, Data!$G:$G, "<" & A1, Data!$H:$H, "=" & A3,Data!$B:$B, "=" & A9)

Where Data!G:G is a column of dates formatted as Short Date, and A1 contains the date 5/1/2018 formatted as a Short Date.

If i remove the date comparison, the formula works again both in excel and VBA.

Any help appreciated.

Justin
 
Upvote 0
Either formula should work,
You should review your data and criteria.


Excel 2010
ABCD
11-May-18
23030
2d
Cell Formulas
RangeFormula
C2=SUMIFS(Data!$D:$D, Data!$G:$G, "<" & A1, Data!$H:$H, "=" & A3,Data!$B:$B, "=" & A9)
D2=SUMIFS(Data!$D:$D, Data!$G:$G, "<" & A1, Data!$H:$H, A3,Data!$B:$B, A9)
 
Upvote 0
Thank you. I realized it was a formatting issue with the data in G:G. I had a formula assembling a data, however adding the DATEVALUE() to the individual dates fixed the issue. I tried reformatting my dates to how you have in your cell A1, and it would not reformat, indicating it was not actually reading as a date. This is fixed now.

Thank you,

Justin
 
Upvote 0
The format of the date does not matter. But it must be a form that Excel recognizes as a date.

Confirm that =ISNUMBER(A1) and =ISNUMBER(Data!G1) for data cell in Data!G:G return TRUE.

Also, unrelated to your problem, replace whole-column ranges like $D:$D with limited ranges like $D$1:$D$10000. Replace 10000 with the max rows you truly expect to use, presumably much less than 1+ million.

Although SUMIFS might be smart enough to compare only then number of rows that have numeric data in Data!D:D, the whole-column ranges is a "bad habit" that get you into trouble with some other functions like IF() and SUMPRODUCT.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,907
Messages
6,122,181
Members
449,071
Latest member
cdnMech

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