Forum Discussion
hrh_dash
Sep 09, 2022Iron Contributor
Macro to sumifs a range of values based on dates
I would like to translate the following excel formula to a macro for the sumifs of values based on dates. Currently I am getting an error msg pop up "Run time error 13 Type mismatch" Excel fo...
- Sep 09, 2022
You have to concatenate with the variable prevdate, and double the quotes in the string.
.Formula = "=SUMIFS(B:B,A:A,"">=""&DATE(YEAR(" & prevdate & "),MONTH(" & prevdate & "),1),A:A,""<=""&EOMONTH(" & prevdate & ",0))"
HansVogelaar
Sep 27, 2022MVP
You're trying to use an Excel formula as VBA code. That won't work. You also forgot the End If belonging to the If ... Then.
If DestwsP.Range("D" & i).Value > DateSerial(Year(Date), Month(Date) - 1, 1) Thenhrh_dash
Sep 27, 2022Iron Contributor
thanks for the help!!