ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   autofilter with variable criteria (https://www.excelbanter.com/excel-programming/375149-autofilter-variable-criteria.html)

dr chuck

autofilter with variable criteria
 
I have the following programming attempting to use the variable CBOX as my
Criteria1 in an autofilter. I get a syntax error on the autofilter line when
i run it. The line works fine if I use "=" as opposed to the "<" which i
want. I am attempting to filter away the variable in CBOX.

========================
Private Sub CheckBox3_Click()
Dim cbox As String
Let cbox = CheckBox3.Caption

If CheckBox3 = False Then
Selection.AutoFilter Field:=40, Criteria1:<cbox

Else
Selection.AutoFilter Field:=40
End If

End Sub

========================
thanks,
dr chuck

Tom Ogilvy

autofilter with variable criteria
 
there is a difference between the < operator and the assignment operator
for an argument. You can't do :<


Selection.AutoFilter Field:=40, Criteria1:="<"&cbox


--
Regards,
Tom Ogilvy




"dr chuck" wrote in message
...
I have the following programming attempting to use the variable CBOX as my
Criteria1 in an autofilter. I get a syntax error on the autofilter line
when
i run it. The line works fine if I use "=" as opposed to the "<" which i
want. I am attempting to filter away the variable in CBOX.

========================
Private Sub CheckBox3_Click()
Dim cbox As String
Let cbox = CheckBox3.Caption

If CheckBox3 = False Then
Selection.AutoFilter Field:=40, Criteria1:<cbox

Else
Selection.AutoFilter Field:=40
End If

End Sub

========================
thanks,
dr chuck




dr chuck

autofilter with variable criteria
 
Thanks Tom,
You always supply a wealth of information.
--
dr chuck


"Tom Ogilvy" wrote:

there is a difference between the < operator and the assignment operator
for an argument. You can't do :<


Selection.AutoFilter Field:=40, Criteria1:="<"&cbox


--
Regards,
Tom Ogilvy




"dr chuck" wrote in message
...
I have the following programming attempting to use the variable CBOX as my
Criteria1 in an autofilter. I get a syntax error on the autofilter line
when
i run it. The line works fine if I use "=" as opposed to the "<" which i
want. I am attempting to filter away the variable in CBOX.

========================
Private Sub CheckBox3_Click()
Dim cbox As String
Let cbox = CheckBox3.Caption

If CheckBox3 = False Then
Selection.AutoFilter Field:=40, Criteria1:<cbox

Else
Selection.AutoFilter Field:=40
End If

End Sub

========================
thanks,
dr chuck






All times are GMT +1. The time now is 08:51 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com