Filter Date

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Trying to filter worksheet on date less than 6/5/2018 using the below code. Perplexed....


Thank you for any help.

Code:
Sub DateLessThan()Dim Lastrow As Long, i As Long
Dim ws As Worksheet
Set ws = ActiveSheet
Dim sdate As String
sdate = 6 / 5 / 2018
Lastrow = Range("A" & Rows.Count).End(xlUp).Row
If ws.AutoFilterMode Then ActiveSheet.AutoFilterMode = False
ws.Range("A1:E1").AutoFilter field:=1, Criteria1:="<=" & sdate




End Sub
 
Thank You Mr Marcelo - This does work - however I'd like to not utilize the worksheet for the desired dates.
 
Upvote 0

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Thank You Mr Marcelo - This does work - however I'd like to not utilize the worksheet for the desired dates.

This worked for me

Code:
Sub FilterArrDates()
    Dim ws As Worksheet, v As Variant
    
    v = Array(DateSerial(2018, 6, 5), DateSerial(2018, 6, 14), DateSerial(2018, 5, 5))
    Set ws = ActiveSheet
    With ws
        .AutoFilterMode = False
        .Range("A1:E1").AutoFilter Field:=1, Criteria1:=v, Operator:=xlFilterValues
    End With
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,223,741
Messages
6,174,230
Members
452,553
Latest member
red83

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