VBA countifs date less than today's date?

completeexcelnoob

New Member
Joined
Jun 20, 2015
Messages
4
Dear all,

I have a range filled with dates as such:

A
1Date
201/07/2015
3
401/08/2015
501/09/2015

<tbody>
</tbody>

I am planning to use Worksheetfunction.countifs to count the number of dates that are smaller than today's date as one criteria. In excel this would have been done with
Code:
=COUNTIFS(A2:A5,"<"&TODAY())
However, I can't for the life of me seem to replicate this in VBA (getting errors). What is also important is that cells with blank dates are not counted at all (i.e. false) as COUNTIFS does.

Many thanks in advance.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Like this?

Code:
Sub test()
Dim A As Long
A = WorksheetFunction.CountIf(Range("A:A"), "<" & Date)
Range("B1").Value = A
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,519
Messages
6,125,294
Members
449,218
Latest member
Excel Master

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