Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there a more efficient way to filter values then populate listbox?

Status
Not open for further replies.

Chats

Technical User
Mar 12, 2002
88
GB
I have set up a VBA userform in Excel 2000. The form has a multiselect 2 column listbox. A sheet called "Index" contains around 7000 rows of data in two columns -

Code | Description

There is a textbox on my form called SearchFor. I have written some code which responds to the change event on SearchFor and runs an advanced filter on the 7000 rows of data to match rows which start with the value in SearchFor.

The listbox is then populated with the filtered list of values.

This works really well, except when SearchFor is blank, at which point there is a small time delay as the data is processed.

My question is this: Is there a more efficient way of achieving what I am attempting to do? I want to keep the spreadsheet "stand-alone" so cannot store the list of values in an external database and run a query.

My code is below in case this helps:

Code:
Private Sub SearchFor_Change()
    
    
    Worksheets("Index").Range("E2").Value = SearchFor
    
    Worksheets("Index").Range("A1:B7218").AdvancedFilter Action:=xlFilterInPlace, CriteriaRange:= _
        Range("D1:E2"), unique:=False
    
    ResultList.Clear
    
    Dim cell As Range, rng As Range

    With Worksheets("Index")
        Set rng = .Range("A2:A" & _
        .Cells(65536, 1).End(xlUp).Row) _
        .SpecialCells(xlCellTypeVisible)
    End With

    With Me.ResultList
        .ColumnCount = 2
            For Each cell In rng
                .AddItem cell
                .List(.ListCount - 1, 1) = cell.Offset(0, 1)
            Next
    End With

End Sub

Any suggestions appreciated - I will try them out and report back which one gave the best performance.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top