• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

How to filter 'Date' with VBA

ThrottleWorks

Excel Ninja
Hi,

I am trying to filter a Date value from a column with VBA.
I need to filter with criteria as 'Equal to or Before' date.

I tried below mentioned line but it is not working. Please note, TheDate is defined as Date in the code and it has a valid value.

Can anyone help me in this please.

Code:
Rng.AutoFilter Field:=DateCol, Criteria1:="<=" & TheDate, Operator:=xlAnd
 
Hi @Asheesh , I am using below mentioned code and it seems to be working fine. Thanks. :)


Code:
Dim TheDateNumber As Long
TheDateNumber = ThisWorkbook.Worksheets("Macro").Range("a1").Value
Rng.AutoFilter Field:=DateCol, Criteria1:="<=" & TheDateNumber, Operator:=xlAnd
 
Back
Top