+ Reply to Thread
Results 1 to 10 of 10

VBA pulling unique results into combobox in userform

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

    VBA pulling unique results into combobox in userform

    All,

    I am having a problem getting the unique values from a pivot table in combobox (cbMU) based on list chosen from combobox 1 (cbTOG)

    right now the codes work for populating both comboxes but the 2nd combobox fills with all the values for MU instead of the unique ones associated to the list in cbTOG
    For example:
    cbTOG has values like 69, 70, 100, 111, 112, 312, 631, 812, 900 and so one
    cbMU has values like 100, 118, 124, 615, 812, 312, and so one

    If I chose under cbTOG the value 69, then cbMU should have 615.
    If I chose under cbTOG the value 113, then cbMU should show 111, 113, 131

    code that fills the combobox 1 aka cbTOG:
    Please Login or Register  to view this content.
    the userform initialize fills cbTOG correctly

    Please Login or Register  to view this content.
    the cbTOG_change populates with the MU numbers but when I choose one of the TOG numbers the MU numbers do not change,
    I don't receive an error either so the code populates both but the cbMU needs to populate with results like what i referred to in the values example.

    I have a photo of what is in the pivot table for reference. can anyone tell me what I am missing in my code?
    I know I may have to supply the workbook but that may take a bit for me to slim it down to what I can divulge since it has company data that I cannot share so if asked I will try and supply a working sample but I will also haev to remove many pieces of code that are used in multiple sheets already.

    If it helps; the pivot table pulls data from the same sheet called 'combined' and the TOG values are in column H and the MU values are in column I
    Last edited by bbqqsmokeman; 09-17-2017 at 07:43 PM.

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

    Re: VBA pulling unique results into combobox in userform

    So after more work I decided to change from looking through a pivot table and went to using the columns on the sheet the data is being housed on.
    I managed to get the combobox 1 (cbTOG) to fill with unique values and remove duplicates. I also thought I solved the second combobox issue by changing to a listbox (lbxMU) as I didn't feel it needed to be used for anything else and a listbox would be better than a combobox as it was only going to display results.

    My new problem is getting the listbox (lbxMU) to show ALL values associated to the chosen value in cbTOG
    Similar to a vlookup but since I am using column H for cbTOG and the values for lbxMU are in column I the vlookup wouldn't work.
    Can anyone assist with what am I missing from my code to get this to work?

    My initialize code loads the cbTOG as seen below:
    Please Login or Register  to view this content.
    The cbTOG in the initialization loads the combobox (cbTOG) and removes duplicates and sorts numerically which is great!

    The lbxMU code loaded in the cbTOG change event loads values in lbxMU but they are not all the values for each cbTOG and are not accurate for some reason.
    Here is the code for filling lbxMU
    Please Login or Register  to view this content.
    I am not certain what I am missing from my code but it doesn't seem to be pulling the correct values.
    example: when I choose 114 in cbTOG then lbxMU should show me 111, 114, 131 but it only shows me 100 which is wrong.
    the lbxMU values are dynamic and will change so I need to have the code do a vlookup type search (results are in column I) and any value associated to cbTOG value picked (pulls from column H) should display in lbxMU.

    Can anyone assist or point me in the right direction?
    Last edited by bbqqsmokeman; 09-17-2017 at 07:45 PM.

  3. #3
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,303

    Re: VBA pulling unique results into combobox in userform

    Just for my understanding, is this what you're after ?
    Attached Files Attached Files
    Last edited by bakerman2; 09-17-2017 at 08:30 PM.
    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.

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

    Re: VBA pulling unique results into combobox in userform

    Bakerman2 you have been there for me and I thank you for all you have done.
    I took a look at what you sent me and it is what I want it to do. So I took the code and removed my original initialization code and replaced it and added the cbTOG code as well to cbTOG_Change and ran it and received a runtime error '-2146233079 (80131509)': Failed to compare two elements in the array.

    Here is my changed codes:

    Please Login or Register  to view this content.
    and

    Please Login or Register  to view this content.
    I am not certain if the other code I use in the initialize code affects it but I don't believe so but can send another 'full' version of my initialize code if needed; but yes it is what I am looking for and alot cleaner than mine; now to get it to work.

    I slimmed down the actual workbook and supplying it for a better understanding what I am getting and possible why I am getting that error.
    Attached Files Attached Files
    Last edited by bbqqsmokeman; 09-17-2017 at 09:09 PM.

  5. #5
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,303

    Re: VBA pulling unique results into combobox in userform

    This should do it.
    Attached Files Attached Files

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

    Re: VBA pulling unique results into combobox in userform

    bakerman2 you are a VBA guru! That works perfectly!
    One quick question that I should've mentioned earlier in part of what I needed is How can I remove duplicates in the lbxMU when it populates?

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,303

    Re: VBA pulling unique results into combobox in userform

    Your wish is my command.
    Attached Files Attached Files

  8. #8
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,303

    Re: VBA pulling unique results into combobox in userform

    And if you want those sorted too.

    Please Login or Register  to view this content.

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

    Re: VBA pulling unique results into combobox in userform

    bakerman2 you constantly amaze me with your knowledge and skills!
    I never even thought about having it sorted, I was so impressed and excited to see it all working but am extremely grateful for you thinking ahead and covering every aspect! Simple response of 'WOW!"
    You are one of the best VBA guys on here! Thank you very much!
    This is perfect! You have solved my dilemna and I am proud to be able to close this off as solved and the solution provider was 'bakerman2'!

    thank you again!
    Last edited by bbqqsmokeman; 09-17-2017 at 10:42 PM.

  10. #10
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,303

    Re: VBA pulling unique results into combobox in userform

    You're very welcome and thanks for rep+.

+ 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 ComboBox to dinamically populate results basis of another combobox
    By rlh in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-05-2017, 06:27 PM
  2. Userform - dependent combobox to select worksheet to return search results and data change
    By ThePeoplesClub in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-29-2016, 01:27 PM
  3. [SOLVED] Unique Values in Combobox in Userform
    By nKife in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-17-2015, 07:45 PM
  4. [SOLVED] Unique items in combobox on userform
    By YasserKhalil in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 08-16-2015, 09:31 AM
  5. [SOLVED] Depanted combobox and results in a textbox, in a UserForm.
    By MariaPap in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-02-2013, 08:17 AM
  6. Userform: Unique Values to ComboBox
    By dinosaur1993 in forum Excel Programming / VBA / Macros
    Replies: 17
    Last Post: 09-21-2013, 03:09 AM
  7. Replies: 17
    Last Post: 10-14-2012, 11:15 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