+ Reply to Thread
Results 1 to 16 of 16

Show filtered data in listbox on a userform

  1. #1
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Show filtered data in listbox on a userform

    Hello,

    In a worksheet I have a list with different kinds or records (errors, warnings, etc). I also have a userform that can show these. What I want to accomplish is that I can use a optionbutton to filter 1 type of record and show that in that listbox of my userform. See attached.

    I am able to show all data in the listbox. And I am also able to filter the data in the table. However, I cannot get only the filtered data in the listbox.

    Please Login or Register  to view this content.
    Attached Files Attached Files

  2. #2
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Show filtered data in listbox on a userform

    Replace your code with this...
    Have only done Errors & Warnings buttons
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by sintek; 12-09-2021 at 06:01 AM.
    Good Luck
    I don't presume to know what I am doing, however, just like you, I too started somewhere...
    One-day, One-problem at a time!!!
    If you feel I have helped, please click on the star to left of post [Add Reputation]
    Also....add a comment if you like!!!!
    And remember...Mark Thread as Solved.
    Excel Forum Rocks!!!

  3. #3
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show filtered data in listbox on a userform

    Hi Sintek,

    I made a few small changes and it does what I need.
    Thanks for helping me in the right direction :-)

    one question in your code..

    Please Login or Register  to view this content.
    why do you not define the variables as a type?
    e.g. Dim Data as Range, Arr as Array, etc

  4. #4
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Show filtered data in listbox on a userform

    If it is not specified it automatically takes on data type Variant
    Above is same as...
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show filtered data in listbox on a userform

    in my mastersheet I call this userform form another worksheet. Then the filtering does not work.
    So, when I move the CommandButton to a second sheet (in my example file) I see this same behavior. Why would that be? Is that because the filter is applied to the active sheet?

  6. #6
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Show filtered data in listbox on a userform

    Add the red snippet in Private Sub LbxPop()
    Please Login or Register  to view this content.
    Last edited by sintek; 12-09-2021 at 06:33 AM.

  7. #7
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show filtered data in listbox on a userform

    I have moved the CommandButton1 to "Sheet1"
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show filtered data in listbox on a userform

    That did it :-)
    Problem solved. :-)

  9. #9
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show filtered data in listbox on a userform

    There is still one tiny issue with the code... When I only have 1 line in the table, then the alignment of the columns is messed up.. :-(

  10. #10
    Forum Contributor
    Join Date
    11-14-2021
    Location
    africa
    MS-Off Ver
    2016 & 2019
    Posts
    255

    Re: Show filtered data in listbox on a userform

    @Kammend did you test optionbutton(Both Errors and Warnings) it doesn't seem to work. it should show all of data as when run the userform from the first time

  11. #11
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Show filtered data in listbox on a userform

    Here...is amended if only 1 row entry...
    Attached Files Attached Files
    Last edited by sintek; 12-09-2021 at 08:03 AM.

  12. #12
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Show filtered data in listbox on a userform

    For both...use code in file above and this snippet
    Please Login or Register  to view this content.

  13. #13
    Forum Expert torachan's Avatar
    Join Date
    12-27-2012
    Location
    market harborough, england
    MS-Off Ver
    Excel 2010
    Posts
    4,302

    Re: Show filtered data in listbox on a userform

    Variation on a theme.
    Attached Files Attached Files
    Torachan,

    Mission statement; Promote the use of Tables, Outlaw the use of 'merged cells' and 'RowSource'.

  14. #14
    Registered User
    Join Date
    01-29-2013
    Location
    The Netherlands
    MS-Off Ver
    2016 x64
    Posts
    48

    Re: Show filtered data in listbox on a userform

    yes, it now works as I want it. Thanks

  15. #15
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,206

    Re: Show filtered data in listbox on a userform

    And one more variation on a theme. The solution uses Recordset.

    I checked all three examples for 100k records. They all managed in an acceptable time.

    Artik
    Attached Files Attached Files

  16. #16
    Forum Expert sintek's Avatar
    Join Date
    12-04-2015
    Location
    Cape Town
    MS-Off Ver
    2013 | 2016 | 2019
    Posts
    13,167

    Re: Show filtered data in listbox on a userform

    Simplification....
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Populate UserForm ListBox with unique values from filtered data
    By karmapala in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-28-2019, 12:54 PM
  2. [SOLVED] Want to Show Filtered data in Listbox with Tickbox Option to Filter data
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-04-2017, 11:55 AM
  3. [SOLVED] Want to Show Filtered data in Listbox with Tickbox Option to Filter data
    By HaroonSid in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-04-2017, 05:49 AM
  4. [SOLVED] How to filter a table using textbox and show filtered data in listbox (userform)
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-01-2017, 10:31 AM
  5. [SOLVED] How to show data in UserForm ListBox from WorkSheet?
    By z-eighty2 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 01-31-2014, 05:26 PM
  6. Userform to show filtered data
    By onsid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-23-2013, 02:56 PM
  7. Using Filtered Data in Userform Listbox
    By sfinney in forum Excel General
    Replies: 0
    Last Post: 03-18-2005, 11:09 AM

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