VBA Sumifs Help

rockchalk33

Board Regular
Joined
Jan 12, 2016
Messages
111
Code:
Sub text2()
Dim userDate As String
Sheets("Sheet11").Select
Range("Z1").Select


userDate = InputBox("Please type a date to search in MM/DD/YYYY format")
If userDate = vbNullString Then Exit Sub


Sheet11.Range("Z1").Value = Application.WorksheetFunction.SumIfs(Range("O:O"), Range("B:B"), userDate, Range("A:A"), "Shop")




End Sub

When this is manually entered using the Excel window, I am obtaining the correct answer...below is the Excel forumula...in this particular example I am using 1/2/2016 as the example for the userDate:

=SUMIFS(O:O,B:B,"1/2/2016",A:A,"Shop")

When the VBA code is ran, there is no value displayed in cell Z1.....can someone please help me with this!
 

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
are your dates in column B formatted as text or as dates? If they're dates, they will not be able to match a string as the actual value of a date is a decimal...

Perhaps convert your userDate string into a date before using it in the sumifs function?
 
Upvote 0
are your dates in column B formatted as text or as dates? If they're dates, they will not be able to match a string as the actual value of a date is a decimal...

Perhaps convert your userDate string into a date before using it in the sumifs function?


Code:
Sub text2()
Dim userDate As Date
Sheets("Sheet11").Select
Range("Z1").Select


userDate = InputBox("Please type a date to search in MM/DD/YYYY format")
If userDate = vbNullDate Then Exit Sub


Sheet11.Range("Z1").Value = Application.WorksheetFunction.SumIfs(Range("O:O"), Range("A:A"), "Shop", Range("B:B"), userDate)




End Sub

I tried the above code and still did not receive an answer. The values in Column B are in the "m/d/yyyy" format. I tried entering both "01/02/2016" as well as "1/2/2016" into the inputbox and neither returned an answer.

What's really throwing me off is if I leave out the input box and rather search exactly for "1/2/2016" I still don't receive an answer:

Code:
Sub text2()
'Dim userDate As Date
Sheets("Sheet11").Select
Range("Z1").Select


'userDate = InputBox("Please type a date to search in MM/DD/YYYY format")
'If userDate = vbNullDate Then Exit Sub


Sheet11.Range("Z1").Value = Application.WorksheetFunction.SumIfs(Range("O:O"), Range("A:A"), "Shop", Range("B:B"), "1/2/2016")




End Sub
 
Last edited:
Upvote 0
So you mean your values in column B are SHOWN as m/d/yyyy.... but they're probably FORMATTED as a date... To see what I mean, select any of your dates in column B and change the number formatting from Date to "General" You will see a strange number.

Dates in excel are not strings of text that can be compared to a user-input string....


Try this.



Code:
Sub text2()
Dim userDate As String
Sheets("Sheet11").Select
Range("Z1").Select


userDate = InputBox("Please type a date to search in MM/DD/YYYY format")
If userDate = vbNullString Then Exit Sub


Sheet11.Range("Z1").Value = Application.WorksheetFunction.SumIfs(Range("O:O"), Range("B:B"), [COLOR=#ff0000]CDate(userDate)[/COLOR], Range("A:A"), "Shop")




End Sub
 
Upvote 0
So you mean your values in column B are SHOWN as m/d/yyyy.... but they're probably FORMATTED as a date... To see what I mean, select any of your dates in column B and change the number formatting from Date to "General" You will see a strange number.

Dates in excel are not strings of text that can be compared to a user-input string....


Try this.



Code:
Sub text2()
Dim userDate As String
Sheets("Sheet11").Select
Range("Z1").Select


userDate = InputBox("Please type a date to search in MM/DD/YYYY format")
If userDate = vbNullString Then Exit Sub


Sheet11.Range("Z1").Value = Application.WorksheetFunction.SumIfs(Range("O:O"), Range("B:B"), [COLOR=#ff0000]CDate(userDate)[/COLOR], Range("A:A"), "Shop")




End Sub

Column B is formatted as a Date and not "General"....Hmmmmmm....Put exactly what you had posted and still striking out. :(
 
Last edited:
Upvote 0
Are you saying you don't see anything at all in Z1 not even a 0 value?
 
Upvote 0
Assuming your settings are not set to suppress the display of zero values, there should be a value of some sort in the cell. Are you sure you're looking at the correct sheet? The code name Sheet11 does not necessarily refer to a sheet whose tab says Sheet11.
 
Upvote 0
Are you running the macro? Just because the macro exists does not mean the cell will automatically be updated. You need to run it from the macro window or create a button and assign the macro to that button.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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