Filter UserForm Multicolumn ListBox with TextBox/ComboBox

Alexandroid

New Member
Joined
Jan 29, 2014
Messages
16
Hi Everyone,


I've been looking for an answer to this specific scenario and I haven't found it yet. If it exists, I'm sorry for wasting your time and would request the link to that answer please.


If not, here we go.


I'm creating a listbox in a userform that's using a rowsource from a sheet to list the multicolumn list.


This list is very big and I want to be able to filter through it using a combobox to specify which column to filter by and a textbox to specify the keywords to filter by.


I've found different iterations of these in pieces but not as a whole and I haven't been able to put it together.


Here is the code I have so far:


Code:
Private Sub UserForm_Initialize()


ListBoxCharges.RowSource = "SourceTable!A1:" & _ Sheets("SourceTable").Range("A1").SpecialCells(xlCellTypeLastCell).Address


With Me.ListBox1
    .MultiSelect = fmMultiSelectMulti
    .ColumnCount = Worksheets("SourceTable").UsedRange.Rows(1).Columns.Count
End With


With Me.comboboxFilter
    For i = 1 To Me.ListBox1.ColumnCount
        If Sheets("SourceTable").Cells(1, i).Value <> "" Then
            .AddItem Sheets("SourceTable").Cells(1, i).Value 'ComboBox is populating from a horizontal headers list.
        End If
    Next i
End With




Private Sub txtboxFilter_Change()


    Dim i As Long
    Dim sCrit As String
    
    'Add asterisks around text for all matches
   'UCase is used to make filter case-insensitive
   sCrit = "*" & Me.txtboxFilter.Text & "*"
    
    With Me.ListBox1
    
        .RowSource = "SourceTable!A1:" & Sheets("SourceTable").Range("A1").SpecialCells(xlCellTypeLastCell).Address
    
        For i = .ListCount - 1 To 0 Step -1
            If Not UCase(.List(i)) Like sCrit Then
                Debug.Print .Selected(i)
                .Selected(i) = False
                .RemoveItem i
            End If
        Next i
        
        .MultiSelect = fmMultiSelectMulti
        .ColumnCount = Worksheets("SourceTable").UsedRange.Rows(1).Columns.Count
    End With


End Sub


I get a "Unspecified Error" (80004005) When I get to the ".RemoveItem i" line which I've read is because I'm using RowSource to populate the list.


Is there an easier what to achieve all this?


Thank you for your help and let me know if you need more information.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Last edited:
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,821
Members
449,049
Latest member
cybersurfer5000

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
Back
Top