Toggle button/checkboxes

xenoborg

New Member
Joined
Jul 3, 2007
Messages
9
I have added some check boxes that will sort my data, in this case removing rows with values of 0. Currently, I have a checkbox with
Code:
Private Sub CheckBox1_Click()
    Selection.AutoFilter Field:=27, Criteria1:="<>0", Operator:=xlAnd
End Sub

It filters the way I want when I check it, but when I uncheck it, it doesn’t go back to what it was before, is this possible to do?

I tried using the same code with a few other button types like toggle, and it did the same thing. I would prefer to use a checkbox, but any type is fine.

Thanks


PS. Its not as important, but I was also wondering if it was possible to reverse it so that it filters things out when its not checked, and doesn’t filter when it is checked.
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.

BrianB

Well-known Member
Joined
Feb 17, 2003
Messages
8,127
Code:
Private Sub CheckBox1_Click()
    If CheckBox1.Value = True Then
        Selection.AutoFilter Field:=27, Criteria1:="<>0", Operator:=xlAnd
    Else
        Selection.AutoFilter Field:=27
    End If
End Sub
 

Forum statistics

Threads
1,181,056
Messages
5,927,864
Members
436,573
Latest member
CMR237

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
Top