+ Reply to Thread
Results 1 to 12 of 12

Need vba code: 2 comboboxes to filter data in a listbox

  1. #1
    Registered User
    Join Date
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    69

    Need vba code: 2 comboboxes to filter data in a listbox

    Hi everyone,

    i have the following code below when selecting an item in ComboBox1 and pressing the CommandButton it will display the result in a listbox.
    The data comes from Sheet1.
    There are 5 columns, and this code filters column A.
    Now my problem is, I have a second ComboBox called ComboBox2.
    ComboBox2 should filter column B.
    I would like, that ComboBox1 and ComboBox2 to be working together, meaning when an item in ComboBox1 and an item in ComboBox2 are selected and the CommandButton is pressed, it will then display the filtered results in the listbox.


    Please Login or Register  to view this content.
    Would you mind helping me out?
    I have been working on this for 2 days already and I just can't figure it out.

    Thanking in advance for any assistance you could provide.
    Last edited by frankytheman; 12-26-2019 at 11:51 AM.

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

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    Hi frankytheman

    Welcome to the Forum...

    Unfortunately, we are only able to assist if you comply with the Forum Rules found here

    Your post does not comply with rule # 2

    2. Programming code must be enclosed in code tags to improve readability. (A, Z)
    Please Login or Register  to view this content.
    To fix...Highlight your code and press the # icon

    Once you fix that please upload a sample file to make use of...
    Last edited by sintek; 12-26-2019 at 11:03 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
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    69

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    Ok, i fixed it. I am not able to upload the file as it has sensitive company infos in it.

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

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    I am not able to upload the file as it has sensitive company infos in it.
    Understandable, however, we can go around in circles providing code that will never work as we have now idea how your actual data file looks...
    Upload a sample file depicting your actual scenario...desensitize the info...

    We have no idea how you are populating your comboboxes...nor the info in the rows and columns...

  5. #5
    Registered User
    Join Date
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    69

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    Ok, just replaced sensitive info from the sheet.
    Here it is.
    Thanks again.
    Attached Files Attached Files

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

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    Please Login or Register  to view this content.
    Last edited by sintek; 12-27-2019 at 01:34 AM. Reason: declared variable in red

  7. #7
    Registered User
    Join Date
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    69

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    OMG!!!! Thank you so much.You are a champ!!!

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

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    .............................................
    Thanks.gif

  9. #9
    Registered User
    Join Date
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    69

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    Hi sintek,
    Just found out something that if ComboBox2 is empty it shows an error message but I have fixed that with an Exit Sub function.
    Would it be possible that if ComboBox2 is empty that it will only filter what is in ComboBox1?

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

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    Change
    Please Login or Register  to view this content.
    To
    Please Login or Register  to view this content.
    PS...Just for interest sake...Another option...
    Please Login or Register  to view this content.
    Last edited by sintek; 12-27-2019 at 06:39 AM.

  11. #11
    Registered User
    Join Date
    12-26-2019
    Location
    Germany
    MS-Off Ver
    2016
    Posts
    69

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    TOP!!! Thank you so very much.It works like magic. No words can describe my gratitude.

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

    Re: Need vba code: 2 comboboxes to filter data in a listbox

    Pleasure...Glad I could help...

+ 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] How to filter a listbox with comboboxes?
    By waimea in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-08-2019, 04:29 PM
  2. [SOLVED] Consolidate repetitive code - (populating two comboboxes from an advanced filter)
    By melpa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-22-2019, 09:06 AM
  3. Replies: 0
    Last Post: 05-06-2019, 03:36 PM
  4. filter data using comboboxes and display in listbox
    By reiiling in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-03-2018, 01:25 AM
  5. 3 Dynamic ComboBoxes to filter data and populate a ListBox
    By Raylou in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 10-05-2018, 05:26 AM
  6. [SOLVED] Filter worksheet data using 4 dependant comboboxes and populate in 'ListBox' on a userform
    By p_nayak268 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-27-2014, 12:41 PM
  7. VBA userform listbox populate data entered from comboboxes
    By Hilton1982 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-05-2012, 11:29 PM

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