Vba: Application.WorksheetFunction.CountIfs with variables

Nelson78

Well-known Member
Joined
Sep 11, 2017
Messages
526
Office Version
  1. 2007
Hello everybody.

I'm tinkering with the following situation:

VBA Code:
cell.value = Application.WorksheetFunction.CountIfs(Sheets(1).Range("B2:B" & lr), ">=" & date1, Sheets(1).Range("B2:B" & lr), "<=" & date2)

The range Sheets(1).Range("B2:B" & lr) is populated only by dates.
In cell I need to count all the dates included in the range delimited by the variablese date1 and date2.

At the moment the result is 0, but it is not correct.

How can I figure it out?

Thank's in advance.
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Try converting the dates using CLng

Rich (BB code):
cell.Value = Application.WorksheetFunction.CountIfs(Sheets(1).Range("B2:B" & lr), ">=" & CLng(date1), Sheets(1).Range("B2:B" & lr), "<=" & CLng(date2))

If that doesn't work show us how you have Dim'd date1 and date2 and how you are populating them and check that column B is being recognised as a date (/number) and not as text.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,315
Messages
6,124,207
Members
449,147
Latest member
sweetkt327

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