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:

[TABLE="class: grid, width: 90"]
<tbody>[TR]
[TD="align: center"][/TD]
[TD="align: center"]A[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]Date[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]01/07/2015[/TD]
[/TR]
[TR]
[TD]3[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]4[/TD]
[TD]01/08/2015[/TD]
[/TR]
[TR]
[TD]5[/TD]
[TD]01/09/2015[/TD]
[/TR]
</tbody>[/TABLE]

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

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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,223,721
Messages
6,174,097
Members
452,542
Latest member
Bricklin

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