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

Excel Joke
Why can't spreadsheets drive cars? They crash too often!
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,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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