Auto Filter and Criteria1 variable

  • Thread starter Thread starter D.S.
  • Start date Start date
D

D.S.

I'm trying to code a worksheet filter by using a variable as < Criteria1 >. The variable < dteFilterDate > will be set by an InputBox, and has been dimensioned as a DATE. The following line of code gives me a run time error #1004, AutoFilter method of Range class failed

Selection.AutoFilter Field:=18, Criteria1:="<= " & dteFilterDate

I've probably got a syntax problem, but haven't found the right combination of characters.

Any ideas?

D.S.
 
This worked for me:

Sub AAA2()
Dim dteFilterDate As Date
dteFilterDate = CDate(InputBox("Enter date"))
Range("AK2").CurrentRegion.Select
Selection.AutoFilter Field:=18, Criteria1:="<= " & CLng(dteFilterDate)
End Sub

--
Regards,
Tom Ogilvy

I'm trying to code a worksheet filter by using a variable as < Criteria1 >.
The variable < dteFilterDate > will be set by an InputBox, and has been
dimensioned as a DATE. The following line of code gives me a run time
error #1004, AutoFilter method of Range class failed

Selection.AutoFilter Field:=18, Criteria1:="<= " & dteFilterDate

I've probably got a syntax problem, but haven't found the right combination
of characters.

Any ideas?

D.S.
 
Thanks again Tom. Just what I needed, worked for me too.

D.S.
This worked for me:

Sub AAA2()
Dim dteFilterDate As Date
dteFilterDate = CDate(InputBox("Enter date"))
Range("AK2").CurrentRegion.Select
Selection.AutoFilter Field:=18, Criteria1:="<= " & CLng(dteFilterDate)
End Sub

--
Regards,
Tom Ogilvy

I'm trying to code a worksheet filter by using a variable as < Criteria1 >.
The variable < dteFilterDate > will be set by an InputBox, and has been
dimensioned as a DATE. The following line of code gives me a run time
error #1004, AutoFilter method of Range class failed

Selection.AutoFilter Field:=18, Criteria1:="<= " & dteFilterDate

I've probably got a syntax problem, but haven't found the right combination
of characters.

Any ideas?

D.S.
 
Back
Top