Making AutoFilter correspond to check box

  • I am trying to use a check box to turn the autofilter on and off on a spreadsheet.


    What I am finding is that the checked box will turn it off. Here is the code that I have:


    Range("B7").AutoFilter


    I tried using an if statement that says when the check box is checked, turn on the filter. When it is unchecked, turn it off. However, it doesn't work that way. with the if statement, I can only run the macro either way when the check box is checked.


    The code above will toggle it on and off.


    Is there a way to ensure that when the check box is checked, the auto filter is on and when it is empty (unchecked), the filter is turned off?


    Thanks

  • Re: Making AutoFilter correspond to check box


    Hi bearcub,


    Assuming that your filter headings are in B1:D1, copy the following code into the worksheet code module:

    Code
    Private Sub CheckBox1_Click()
        If CheckBox1 = True Then
            Range("B1:D1").AutoFilter
        Else
            ActiveSheet.AutoFilterMode = False
        End If
    End Sub


    Hope this helps.


    Regards,
    Batman.

    [COLOR="Purple"]Regards,[/COLOR]
    [COLOR="Purple"]Batman.[/COLOR]

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!