Consulting

Results 1 to 11 of 11

Thread: Populate List Box in Excel with visible rows when worksheet gets filtered

  1. #1
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location

    Populate List Box in Excel with visible rows when worksheet gets filtered

    Hi,

    In my workbook; the column “B” of rows 5 and 6 contain the serial Number “0697”.

    Row 7 of the same column has the text “0698”. And again the same column of row 8 has the serial Number “0697”.

    Supposing I want to filter all the rows that have “0697” from my user form list box I get only the rows 5 and 6 filtered in the list box even though the worksheet shows all the three rows where it contains the text “0697”.

    How could I change the code so that it populates the list box with all the three rows where it contains the text “0697”.


    I've attached the workbook for your reference.

    Any help on this would be kindly appreciated.
    Best Regards,
    adamsm

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    see if the attached does anything for you.

    Your code only added the first area of the xlVisiblecells range.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    Thanks p45cal It does do what I have asked.
    Best Regards,
    adamsm

  4. #4
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    If I may ask, how could I make the column headers visible in the list box. It does not make visible by enabling form the properties window.
    Best Regards,
    adamsm

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You have to bind the data to the listbox to get headings.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  6. #6
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    Like how?!
    Best Regards,
    adamsm

  7. #7
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You have to set the RowSource property of the ListBox, but you don't want a contiguous dataset, you want the filtered results, and you cannot bind to that unless you copy it off somewhere else.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  8. #8
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    Thanks for the reply Xld. I'll try to figure that out.
    Best Regards,
    adamsm

  9. #9
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    For a non-contiguous range, you'll have difficulty using rowSource, even more difficult to use ColumnHeaders. In the past I have used a hidden sheet to prepare a range to use as a RowSource for a list box with ColumnHeaders
    There is such a hidden sheet called DataList in the attached.

    Quote Originally Posted by adamsm
    Like how?!
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by p45cal
    For a non-contiguous range, you'll have difficulty using rowSource, even more difficult to use ColumnHeaders.
    Read ... can't!
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  11. #11
    VBAX Contributor
    Joined
    Apr 2010
    Posts
    182
    Location
    Thanks for the Help p45cal. I could view the column headers now.
    Best Regards,
    adamsm

Posting Permissions

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