+ Reply to Thread
Results 1 to 10 of 10

Running multiple checkbox filters

Hybrid View

  1. #1
    Registered User
    Join Date
    10-22-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Running multiple checkbox filters

    Hi all,

    I have some coding that allows me to filter my data with the use of check boxes that you guys helped me out with earlier in the week. It works perfectly in almost all aspects. The only issue I have is that now I have multiple columns with check boxes assigned to each column. When I select one check box for a specific column it filters the data, as it should, but then when I check a box from another column it only filters that column and erases the first column filtering.

    So, I have four columns each with their respective check boxes and I would like to be able to check some boxes in column B have it filter data and then check boxes in column C and have it keep the filtering from column A.

    See attached for my workbook. Any help would be much appreciated!!!
    Attached Files Attached Files

  2. #2
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Running multiple checkbox filters

    Hi pjohnson05

    Try the code in the attached. Let me know of issues.
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  3. #3
    Registered User
    Join Date
    10-22-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Running multiple checkbox filters

    Your the man!!! This is great! I'm jealous of your VBA skills!

    I do have one question though...what does the following code perform?

    Public Flag As Boolean
    Option Explicit
    
    Sub Update_CheckBoxAll()
        Dim i As Long
    
        Flag = True
        With ActiveSheet
            On Error Resume Next
            .ShowAllData
            On Error GoTo 0
    
            For i = 11 To 22
                .OLEObjects("Checkbox" & CStr(i)).Object.Value = False
            Next
    
            For i = 2 To 10
                .OLEObjects("Checkbox" & CStr(i)).Object.Value = False
            Next
    
            .OLEObjects("Checkbox" & CStr(1)).Object.Value = False
        End With
        Flag = False
    End Sub

  4. #4
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Running multiple checkbox filters

    Hi pjohnson05

    The code you asked about clears all checkboxes (sets them to False) and unfilters all data (ShowAllData). If you want all CheckBoxes in Column B Checked (set to True) after selecting All simply change this line of code
    For i = 2 To 10
                .OLEObjects("Checkbox" & CStr(i)).Object.Value = False
            Next
    to
    For i = 2 To 10
                .OLEObjects("Checkbox" & CStr(i)).Object.Value = True '<-------
            Next
    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

  5. #5
    Registered User
    Join Date
    10-22-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Running multiple checkbox filters

    Okay....thanks! Another question if you don't mind...

    I would like to hide all the drop down arrows from the autofilter. I have found a little macro that will perform this for me but I'm not sure where to insert the "call" line item that will call this other macro. When I place it down at the bottom just before the "application.screenupdating = true" it hides the drop down arrows but then doesn't filter my data. Maybe you have a better way of performing this task. See below for what I have done...

    This is where i have inserted the "call"...

    Sub Filter_Sheet()
        Dim LR As Long
        Dim cBoxB As Variant
        Dim cboxC As Variant
        Dim cboxD As Variant
        Dim cboxF As Variant
        Dim B As Long
        Dim c As Long
        Dim D As Long
        Dim F As Long
    
        ReDim cBoxB(0)
        ReDim cboxC(0)
        ReDim cboxD(0)
        ReDim cboxF(0)
    
        If Flag = True Then Exit Sub
        Application.ScreenUpdating = False
        With Sheets("Dashboard")
            .AutoFilterMode = False
            LR = .Cells.Find("*", .Cells(Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
                    SearchDirection:=xlPrevious).Row
    
            For B = 2 To 15
                If .OLEObjects("Checkbox" & CStr(B)).Object.Value = True Then
                    cBoxB(UBound(cBoxB)) = .OLEObjects("Checkbox" & CStr(B)).Object.Caption
                    ReDim Preserve cBoxB(UBound(cBoxB) + 1)
                End If
            Next B
    
            On Error Resume Next
            ReDim Preserve cBoxB(UBound(cBoxB) - 1)
            On Error GoTo 0
    
            For c = 17 To 19
                If .OLEObjects("Checkbox" & CStr(c)).Object.Value = True Then
                    cboxC(UBound(cboxC)) = .OLEObjects("Checkbox" & CStr(c)).Object.Caption
                    ReDim Preserve cboxC(UBound(cboxC) + 1)
                End If
            Next c
    
            On Error Resume Next
            ReDim Preserve cboxC(UBound(cboxC) - 1)
            On Error GoTo 0
    
            For D = 21 To 28
                If .OLEObjects("Checkbox" & CStr(D)).Object.Value = True Then
                    cboxD(UBound(cboxD)) = .OLEObjects("Checkbox" & CStr(D)).Object.Caption
                    ReDim Preserve cboxD(UBound(cboxD) + 1)
                End If
            Next D
    
            On Error Resume Next
            ReDim Preserve cboxD(UBound(cboxD) - 1)
            On Error GoTo 0
    
            For F = 30 To 31
                If .OLEObjects("Checkbox" & CStr(F)).Object.Value = True Then
                    cboxF(UBound(cboxF)) = .OLEObjects("Checkbox" & CStr(F)).Object.Caption
                    ReDim Preserve cboxF(UBound(cboxF) + 1)
                End If
            Next F
    
            On Error Resume Next
            ReDim Preserve cboxF(UBound(cboxF) - 1)
            On Error GoTo 0
    
            If IsError(Application.Match("*", (cBoxB), 0)) Then
                MsgBox "No Fund/JV Selected. Showing all data."
                Exit Sub
            End If
    
            If Not .AutoFilterMode Then
                .Range("A32").AutoFilter
                .Range("A32:J" & LR).AutoFilter Field:=2, Criteria1:=Array(cBoxB), Operator:=xlFilterValues
                If Not IsError(Application.Match("*", (cboxC), 0)) Then
                    .Range("A32:J" & LR).AutoFilter Field:=3, Criteria1:=Array(cboxC), Operator:=xlFilterValues
                End If
                If Not IsError(Application.Match("*", (cboxD), 0)) Then
                    .Range("A32:J" & LR).AutoFilter Field:=4, Criteria1:=Array(cboxD), Operator:=xlFilterValues
                End If
                If Not IsError(Application.Match("*", (cboxF), 0)) Then
                    .Range("A32:J" & LR).AutoFilter Field:=7, Criteria1:=Array(cboxF), Operator:=xlFilterValues
                End If
            End If
        End With
        Call HideArrows
        Application.ScreenUpdating = True
        
    End Sub
    And this is the macro that its calling...

    Sub HideArrows()
    'hides all arrows except column 11
    Dim c As Range
    Dim i As Integer
    i = Cells(31, 1).End(xlToRight).Column
    
    
    For Each c In Range(Cells(31, 1), Cells(31, i))
     If c.Column <> 11 Then
      c.AutoFilter Field:=c.Column, _
        Visibledropdown:=False
     End If
    Next
    
    
    End Sub

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Running multiple checkbox filters

    Hi pjohnson05

    I think I'd put it right here
    If Not .AutoFilterMode Then
                .Range("A32").AutoFilter
                
                Call HideArrows                  '<---------------------------
                
                .Range("A32:J" & LR).AutoFilter Field:=2, Criteria1:=Array(cBoxB), Operator:=xlFilterValues
                If Not IsError(Application.Match("*", (cboxC), 0)) Then
                    .Range("A32:J" & LR).AutoFilter Field:=3, Criteria1:=Array(cboxC), Operator:=xlFilterValues
                End If
                If Not IsError(Application.Match("*", (cboxD), 0)) Then
                    .Range("A32:J" & LR).AutoFilter Field:=4, Criteria1:=Array(cboxD), Operator:=xlFilterValues
                End If
                If Not IsError(Application.Match("*", (cboxF), 0)) Then
                    .Range("A32:J" & LR).AutoFilter Field:=6, Criteria1:=Array(cboxF), Operator:=xlFilterValues
                End If
            End If
        End With
        Application.ScreenUpdating = True
    End Sub

  7. #7
    Registered User
    Join Date
    10-22-2012
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    12

    Re: Running multiple checkbox filters

    As usual....works perfect there. Many thanks!!!

  8. #8
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Running multiple checkbox filters

    Hi pjohnson05

    You're welcome...glad I could help.

  9. #9
    Registered User
    Join Date
    07-29-2013
    Location
    india
    MS-Off Ver
    Excel 2010
    Posts
    1

    Re: Running multiple checkbox filters

    Hi, in above workbook from pjohnson05, is it possible to create independent filters for column B,C,D&F. In current workbook, filters in column C,D&F are only working if I select atleast one value in column B but I am in a situation where I wanted to create independent checkbox filters in multiple columns....regards, Vijay

  10. #10
    Forum Contributor arlu1201's Avatar
    Join Date
    09-09-2011
    Location
    Bangalore, India
    MS-Off Ver
    Excel 2003 & 2007
    Posts
    19,166

    Re: Running multiple checkbox filters

    vijaybodar,

    Unfortunately you need to post your question in a new thread, it's against the forum rules to post a question in the thread of another user. If you create your own thread, any advice will be tailored to your situation so you should include a description of what you've done and are trying to do. Also, if you feel that this thread is particularly relevant to what you are trying to do, you can surely include a link to it in your new thread.
    If I have helped, Don't forget to add to my reputation (click on the star below the post)
    Don't forget to mark threads as "Solved" (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code: [code] Your code here [/code]

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1