find dates vba problem

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I have the code that is suppose to find all dates older then 3yrs. However I'm confuse as to why is not giving me the intended results.

The first code works as expected....

Code:
MsgBox WorksheetFunction.CountIf(Range("D15:D100"), "<11/30/2015")

However, when I replace the "Hard" date with a dynamic date, it does not give me the intended results. I have 2 dates that are older then 3 yrs, however the results return zero. Any clue as to why??

Code:
MsgBox WorksheetFunction.CountIf(Range("D15:D100"), "< Month(Date), Format(WorksheetFunction.EoMonth(Date, 0), ""dd""), Year(Date) - 3")

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
I think this should work...

Code:
[table="width: 500"]
[tr]
	[td]MsgBox WorksheetFunction.CountIf(Range("D15:D100"), "<" & WorksheetFunction.EoMonth(Date, -36))[/td]
[/tr]
[/table]
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,244
Members
452,622
Latest member
Laura_PinksBTHFT

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