+ Reply to Thread
Results 1 to 4 of 4

Problems with filter from selection in listbox

Hybrid View

  1. #1
    Registered User
    Join Date
    03-15-2013
    Location
    Annan, Scotland
    MS-Off Ver
    2010
    Posts
    17

    Problems with filter from selection in listbox

    I'm working on a relatively simple skills matrix for work and i want to have 2 or 3 list boxes so i can filter by employee, department and possibly skill (although im not sure that's possible the way i have the data laid out.
    I can filter the data manually however not all users of the sheet will want to do it this day so listboxes with a command button seemed ideal however i just cant get it to work at all or find a solution online.
    I've attached a copy of my sheet and any help would be greatly recieved
    Attached Files Attached Files
    Last edited by thmsjlmnt; 03-16-2013 at 04:30 PM.

  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: Problems with filter from selection in listbox

    Hi thmsjlmnt

    This Code is in the attached and appears to do as you describe. Please notice I've added some Dynamic Named Ranges to Data Sheet.
    Let me know of issues...
    Option Explicit
    
    Sub Clear_Filter()
        On Error Resume Next
        ActiveSheet.ShowAllData
        On Error GoTo 0
    End Sub
    
    Sub Filter_Dept()
        Dim i As Integer, cnt As Integer
        Application.ScreenUpdating = False
        Call Clear_Filter
        With ActiveSheet.ListBoxes("List Box 4")
            For i = 1 To .ListCount
                If .Selected(i) Then
                    ActiveSheet.Range(("A5"), Range("A5").End(xlDown)).AutoFilter Field:=1, Criteria1:=.List(i)
                End If
            Next i
        End With
        Application.ScreenUpdating = True
    End Sub
    
    Sub Filter_Emp()
        Dim i As Integer, cnt As Integer, myCol As Long
        Application.ScreenUpdating = False
        Call Clear_Filter
        With ActiveSheet.ListBoxes("List Box 19")
            For i = 1 To .ListCount
                If .Selected(i) Then
                    ActiveSheet.Range(("A5"), Range("A5").End(xlDown)).AutoFilter Field:=2, Criteria1:=.List(i)
                End If
            Next i
        End With
        Application.ScreenUpdating = True
    End Sub
    
    Sub Filter_Skill()
        Dim i As Integer, cnt As Integer, myCol As Long
        Application.ScreenUpdating = False
        Call Clear_Filter
        With ActiveSheet.ListBoxes("List Box 23")
            For i = 1 To .ListCount
                If .Selected(i) Then
                    myCol = WorksheetFunction.Match(.List(i), Rows("5:5"), 0)
                    ActiveSheet.Range(Cells(5, 1), Cells(5, 1).End(xlDown)).AutoFilter Field:=myCol, Criteria1:="<>"
                End If
            Next i
        End With
        Application.ScreenUpdating = True
    End Sub
    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
    03-15-2013
    Location
    Annan, Scotland
    MS-Off Ver
    2010
    Posts
    17

    Re: Problems with filter from selection in listbox

    Thanks very much greatly appreciated

  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: Problems with filter from selection in listbox

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

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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