Results 1 to 5 of 5

Thread: Visual Basic listbox search function

  1. #1

    Visual Basic listbox search function


    Im trying to make a search function for my listbox. I want it to happen in the following way:
    When you type in the textbox txbSearch, all rows that have nothing to do with the search text are removed from the listbox or are invisible.
    If possible i want the search function to search all columns at once.
    My listbox is currently set up in the following way:
    Set r = Range("T1").CurrentRegion
        Set r = r.Offset(1).Resize(r.Rows.Count - 1)
        With Lsb1
            .ColumnCount = r.Columns.Count
            .RowSource = r.Address
            .ColumnHeads = True
        End With
    Does anybody know how to do this?

    Thanks in advance

  2. #2
    VBAX Expert
    Sep 2016
    1)You want to display column header? You can use label as a substitute.

    2)Only remove data? you don't need to add data?

    3)Do you know ListView control?

  3. #3
    Yeah I do want to display the column header. It works just the way I want it to.

    I don't need to add data.

    I can't seem to find this Listview control. What is it?

  4. #4
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    May 2004
    There are 3 possibilities I can see to do it as previously as hiding rows in the source is not an option:
    1. Make an edited copy of the table and display that on the userform (or a similar one)
    2. Delete the rows from the table
    3. Move the rows to the bottom of the table
    Could any of these work for you? (not knowing what your form is intended to do)
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.

    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    My form is supossed to display columns which give information about articles. Each row holds one article.
    I think the best way to do this is to temporary remove the rows that do not have anything in common with the search text.
    Do you have an idea on how I can do this?

Posting Permissions

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