+ Reply to Thread
Results 1 to 13 of 13

Filling 2 seperate listboxes with different values based on combobox choices

  1. #1
    Registered User
    Join Date
    11-25-2015
    Location
    Manitoba
    MS-Off Ver
    2016
    Posts
    36

    Filling 2 seperate listboxes with different values based on combobox choices

    Hello all,
    I have had great help from some who I believe are experts and have been teaching me as I learn vba. The last instance I had assistance with filling a listbox based on another listbox value chosen and that worked great! I have been asked to make a few changes to the userform to now have the listbox populated based on a combobox name chosen but it doesn't end there. The combobox has names in it and when a name is chosen the 1st listbox should populate with specific values associated to the name and the 2nd combobox should populate with values associated to the 1st listbox values. I managed to populate the combobox and the 1st listbox (not associated-having problems still) and the 2nd listbox fills correctly but only if I choose a value from 1st listbox which now needs to change to have those results populated the same but based on combobox chosen name.
    I also need the values in each boxes to be not duplicated. Plus I need to find a way to populate the 3rd listbox with the 2nd listbox values from a different sheet (pivot table).

    Example:
    Combobox -choose Dir1 (column A)and 1st listbox fills with all values (not duplicated) from Column B and 2nd listbox fills with values (column D) associated to 1st listbox and 3rd listbox filled with values from pivot table (same values as listbox2 but different sheet-which houses pivot table summary) and all listbox results stemmed from combobox chosen value.

    I think I explained that correctly and if not I can further explain or try to explain it better.

    I am supplying a slimmed down version of the workbook should anyone want to see what I am trying to do

    Please Login or Register  to view this content.
    The initialize code above works fine.

    The cmbMU code below works but doesn't associate to the correct cmbDirNames values
    Please Login or Register  to view this content.
    The following code below works when I click a value in lbxMU and fills the mbxTOG correctly but it needs to auto-populate based on cmbDirNames
    Please Login or Register  to view this content.
    The 3rd listbox I have not begun to try to build the code but do know I can use the getpivot code if have too but uncertain if that will work

    Not certain what I am missing to make this work (with exception of pivot table results for listbox 3) that I haven't started yet since I am stuck at this point
    Attached Files Attached Files
    Last edited by bbqqsmokeman; 09-25-2017 at 09:24 PM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    ArrayList will not sort the data like "Dir1, Dir2, Dir11, etc" properly.
    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    11-25-2015
    Location
    Manitoba
    MS-Off Ver
    2016
    Posts
    36

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    jindon, your code revisions look alot more complex than what I am used too but appreciate what you have done. I don't know if I explained myself accurate enough and apologize if I haven't. The Dir1, Dir2 etc populate correctly but when I choose one of them the MU and TOG should populate immediately (without clicking in them) and the TOG (lbxTOG) is pulling from column C and it needs to come from column D. The lbSummary should pull from the Dir_Version sheet (same values as what the lbxTOG has. So if I choose Dir1 in the combobox lbxMU fills with MU numbers from column B and lbxTOG from column D and lb|Summary from sheet Dir_Version. Hope that makes more sense

  4. #4
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    Try this one for lbxMU and lbxTOG.
    Attached Files Attached Files
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  5. #5
    Registered User
    Join Date
    11-25-2015
    Location
    Manitoba
    MS-Off Ver
    2016
    Posts
    36

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    bakerman2 that works great! I never thought of using 2 array lists in the cmbDirNames. This is exactly what I am looking for and now I can work on the lbsummary! The 2 listboxes populating was throwing me for a loop and you solved it with ease! thank you very much!!!
    Last edited by bbqqsmokeman; 09-25-2017 at 11:16 PM.

  6. #6
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    Thanks for feedback and rep+.

    1. What jindon ment by the sorting is that when you have f.i. Dir1 to Dir30 it'l sort like Dir1, Dir11,Dir12....Dir19,Dir2,Dir21 .....and so on.
    In that case you need another sorting algorithm. The code jindon provided for sorting is a nice bonus but since you say that filling the combobox worked fine for you, it's a bit of overkill in this case.

    2. As of retrieving results from a PT I've never tried that before so I should have to look into that.
    I'm certainly not an expert on PT's but I suppose it's the combined results of a very large table. Maybe there's another approach possible ?

  7. #7
    Registered User
    Join Date
    11-25-2015
    Location
    Manitoba
    MS-Off Ver
    2016
    Posts
    36

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    Don't get me wrong jindon has some fine code and for me it looks really complex but it does what it should using the click the box method and what's nice is it pulls into the lbSummary which I am going to see if I can incorporate some of his code to make the PT work. I am always looking for best approaches and always open to ideas that would or could work. Both you and jindon are super excel guru's in my opinion and I have no problems giving you both reputation approvals since you both at least took the time to review my issue and took it a step further and showed me some different perspective to get results which nobody has to do but still you guys still amaze me with your knowledge and skills.

  8. #8
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    Is this how you wanted?
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by jindon; 09-25-2017 at 11:37 PM. Reason: One line moved.

  9. #9
    Registered User
    Join Date
    11-25-2015
    Location
    Manitoba
    MS-Off Ver
    2016
    Posts
    36

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    jindon! you are awesome! This is exactly what I needed. I definitely have to look over your code so I understand better how you pulled the pivot table values. Simply wow! You and bakerman2 are unbelievable in your skills! Thank you very much! I am closing this post as resolved thanks to you both. Hopefully one day I will get as good as you both before I retire.

  10. #10
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    You are welcome and thanks for the rep.

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED.

  11. #11
    Registered User
    Join Date
    11-25-2015
    Location
    Manitoba
    MS-Off Ver
    2016
    Posts
    36

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    jindon, out of curiosity where in the code would I place the values that are pulled from the pivot table to be no decimals? When the lbSummary pulls the values only a few of them have values like 879.97867543 when it would be ideal to have them with no decimal placement. Just curious...thanks again

  12. #12
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,524

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    Just replace "Initialize" event code with this one.
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    11-25-2015
    Location
    Manitoba
    MS-Off Ver
    2016
    Posts
    36

    Re: Filling 2 seperate listboxes with different values based on combobox choices

    Awesome! thank you jindon that worked out great!

+ 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] UserForm that Filters choices based comboBox entry
    By BrownBoy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-06-2015, 07:53 PM
  2. [SOLVED] Filling cells into template based on selection with data in seperate sheets
    By lukestkd in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-09-2013, 06:54 PM
  3. [SOLVED] Populate user form based on combobox choices
    By zardof in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 09-20-2012, 11:08 AM
  4. Filling Combobox Based on another combobox.text value.
    By D_Rennie in forum Excel Programming / VBA / Macros
    Replies: 20
    Last Post: 02-18-2012, 01:20 AM
  5. Filling Textbox based on Combobox selection
    By Borg in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-22-2009, 02:55 AM
  6. Filling cells with text in them based on a seperate source worksheet
    By MattLinkus in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-01-2007, 12:29 PM
  7. [SOLVED] Multi Listboxes with data dependent upon user choices
    By SaturnGolfBoy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2006, 08:55 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