Column Formatting by Date in VBA

fben96

New Member
Joined
Jul 30, 2018
Messages
15
Hi,

I am trying to autoFilter a column by date. I have a whole bunch of dates inthis column. Out of date would be to filter the dates that are older than fiveyears old. and Expires within 6 months would be filter the dates between 4.5years and 5 years. Both filters from todays date. This is the code I amcurrently running but it hides all.
Code:
Sub RoundedRectangle12_Click()
Range("a5").Select
Selection.AutoFilter Field:=7, Criteria1:=">=Date-365*5+1"
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Hi

Try the below revised line & see if it does the job


Selection.AutoFilter Field:=7, Criteria1:=">=" & clng(Date-365*5+1)
 
Upvote 0
I tied
Code:
Sub RoundedRectangle15_Click()
Range("a5").Select
Selection.AutoFilter Field:=7, Criteria1:=">=" & CLng(Date - 365 * 5 + 1), Criteria2:="<=" & CLng(Date - 365 * 4.5 + 1)
End Sub
 
Upvote 0
I think this might be a little bit more accurate for the dates

Code:
Sub RoundedRectangle15_Click()
Rows(5).AutoFilter Field:=7, Criteria1:=">=" & CLng(DateAdd("m", -60, Date)), Criteria2:="<=" & CLng(DateAdd("m", -54, Date))
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,865
Messages
6,121,988
Members
449,060
Latest member
mtsheetz

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