Link to home
Start Free TrialLog in
Avatar of Randy Downs
Randy DownsFlag for United States of America

asked on

Office 365 - EXCEL VBA SUMIFS with Variable Date

I can sum spreadsheet values based on the dates entering them manually like this. Dates are in column B and dollar values in column N.
SUMIFS(N4:N144,B4:B144,">=2015-02-09",B4:B144,"<=2015-02-14")

Open in new window


I have issues trying it like with date variables: week7_start, week7_end. I don't get anything summed doing it this way.
SUMIFS(N4:N144,B4:B144,">="&week7_start,B4:B144,"<="&week7_end)

Open in new window


I have tried using Clng & CDate but it doesn't seem to matter. What am I missing?
SUMIFS(N4:N144,B4:B144,">="&Clng(week7_start),B4:B144,"<="&Clng(week7_end))

Open in new window


Here's what the output looks like on my spreadheet.

Week            Start Date      End Date      
Week 7       $(93.31)      8-Feb      14-Feb      Manual dates
                        
                        
Week 7       $-         8-Feb      14-Feb      Variable dates
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

How are you defining "week7_start" or "Clng(week7_start)"?

I don't recognise those as standard Excel functions.

Do you have a User Defined Function to generate the dates?

Thanks
Rob H
ASKER CERTIFIED SOLUTION
Avatar of Rob Henson
Rob Henson
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Randy Downs

ASKER

I am defining variables on a separate worksheet and giving them names to make them easily recognizable in my formulas. The variables week7_start week7_end are formatted as dates like:  8-Feb      14-Feb. Perhaps the issue is not displaying the year.

The idea is to update my variables once a quarter and then all my formulas will follow suit. There will be 14 weeks when I am done.

 It's really not VBA at this point. Sorry I misled you.
I notice that when I format the dates as month/day/year rather than just day/month I end up with 2014 rather than the expected 2015. I have re-used an old spreadsheet so maybe that's the issue.
Now the formulas work. They were apparently trying to compare last year's date. Thanks for your suggestions to get me started in the right direction.

SUMIFS(N4:N144,B4:B144,">="&Clng(week7_start),B4:B144,"<="&Clng(week7_end))

Open in new window