+ Reply to Thread
Results 1 to 10 of 10

VBA code to show filtered results in a Listbox

  1. #1
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    VBA code to show filtered results in a Listbox

    Hello all, please see the attached file. Column A in the 2nd sheet has the master list (which will be updated to add more lines in the future). The remaining columns are storage boxes that contain various food plant seeds as shown.

    What do I need help with? - In the drop down Combo Boxes in Parameters 1-5, I would like the five drop down Combo Boxes to populate the Seeds list column A in the 2nd sheet. When parameters are entered and the Show Storage Boxes button is pressed, I would like to see the relevant storage boxes show up in the list box as shown. In this example, only Storage Box 1, 3, 4, 7 and 8 contain a match for the seeds selected via the Parameter drop down Combo Boxes.

    If you can please help to code the UserForm1 to try to achieve this task, it would be appreciated. Also, instead of having multiple 'Parameter' drop down Combo Boxes (five in this example) - if you can perhaps suggest a better option - maybe a multi-select combo box, where one can choose all their parameters (seeds) and then click the command button and have the List Box populate the data then that works too.

    Note: the list box, which shows the results after the button is pressed, should always be empty by default and it should only populate with data when the button is clicked.

    Thank you!

    April 15 - 2025 image example of result.png
    Attached Files Attached Files
    If you have received help from a user, please feel free to Rep that person.
    Also, do remember to click Thread Tools and mark your thread as solved, if you have achieved a solution to your thread.

  2. #2
    Forum Moderator zbor's Avatar
    Join Date
    02-10-2009
    Location
    Croatia
    MS-Off Ver
    365 ProPlus
    Posts
    16,058

    Re: VBA code to show filtered results in a Listbox

    Here, try this:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Never use Merged Cells in Excel

  3. #3
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,908

    Re: VBA code to show filtered results in a Listbox

    Please Login or Register  to view this content.
    with USERFORM2 using multi-select listbox
    Attached Files Attached Files
    Last edited by JohnTopley; 04-16-2025 at 04:03 PM.
    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  4. #4
    Forum Expert ByteMarks's Avatar
    Join Date
    07-23-2018
    Location
    UK
    MS-Off Ver
    O365 32bit (Windows)
    Posts
    3,086

    Re: VBA code to show filtered results in a Listbox

    Here's my effort.
    Includes select/deslect all and a hook to the mouse wheel.
    I used formulas on the Lists sheet to get the boxes and list of seeds.

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

  5. #5
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: VBA code to show filtered results in a Listbox

    Hello and thank you zbor. Your method works fine but when multiple parameters are selected, only the boxes with the common parameters are returned. What I would like to have returned in the list are all the boxes where those parameters are present as shown below. Also, if there is a storage box where 2 or more selected parameters are present in, then don't return them in the list as duplicates but only list the storage box once.

    zbor - example.png
    Last edited by chin67326; 04-18-2025 at 07:30 PM.

  6. #6
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: VBA code to show filtered results in a Listbox

    Hello JohnTopley, you have a unique approach - thank you. Is it possible to tweak this to get the result as shown below?

    topley - example.png

  7. #7
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: VBA code to show filtered results in a Listbox

    Thank you for this ByteMarks. This is quite another way to approach it. I got some debugging errors a few times but API approaches has created these errors in the past. I think it is a software thing. Thank you nonetheless!

  8. #8
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,908

    Re: VBA code to show filtered results in a Listbox

    Please Login or Register  to view this content.
    Limited to selection of 8 seed types!
    Attached Files Attached Files
    Last edited by JohnTopley; 04-19-2025 at 03:45 AM.

  9. #9
    Forum Expert
    Join Date
    05-05-2015
    Location
    UK
    MS-Off Ver
    Microsoft Excel for Microsoft 365 MSO (Version 2402 Build 16.0.17328.20068) 64-bit
    Posts
    30,908

    Re: VBA code to show filtered results in a Listbox

    Version with headings ..

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

  10. #10
    Forum Contributor
    Join Date
    06-07-2014
    Posts
    218

    Re: VBA code to show filtered results in a Listbox

    Quote Originally Posted by JohnTopley View Post
    Version with headings ..

    Please Login or Register  to view this content.
    This solution works for me - thanking you! I will mark this as solved.

+ 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] Show filtered data in listbox on a userform
    By kammend in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 12-09-2021, 10:34 AM
  2. [SOLVED] using listbox to show results and to remove entry upon match.
    By Hazel56 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-21-2020, 07:20 PM
  3. show filtered results from row 4
    By anilpatni1234 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-22-2018, 08: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] Force ListBox to show the exactly word entered in results
    By matt-43 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-15-2016, 06:57 AM
  6. [SOLVED] Code help: Copy only filtered range to ListBox
    By onmyway in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 02-06-2015, 04:50 AM
  7. Userform:Search through all ws / show results in Listbox
    By wali in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 01-22-2015, 09:56 PM

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