+ Reply to Thread
Results 1 to 28 of 28

Combobox and two listBoxes

  1. #1
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Combobox and two listBoxes

    Hi vba Programmers,

    I am tired of trying to do it but I am not able to get the results since I lack of knowledge. I want to populate a combo box and two listboxes with unique values+ visible cells only. That means when i apply a filter on the sheet I want the combobox and both listboxes to be updated with the filter applied.

    I also try to link combobox1 with two listboxes and make them both multiselect ones, but they are not populated.

    To sum up, when I choose a unique value in combobox1, I want to see all the values matching that item from combobox1 in listbox1 and listBox2.

    This is my poor code: (please also take a look to the sample workbook)

    Please Login or Register  to view this content.
    Thank you in advance guys. Advise me please.
    Attached Files Attached Files

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Combobox and two listBoxes

    Which sheet should the listboxes be populated from and which column is the combobox being used to filter?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    I am using sheet1 as worksheet and for combobox it is populated from Column A, ListBox 2 from Column B and ListBox3 from column C. the filter could be applied to any of the three columns.

    Thank you

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Combobox and two listBoxes

    Sorry I'm not really following, Sheet1 only has 1 column of data.

    Sheet2 has 3 columns of data but I can't see how any of the values in column 1 Sheet1 could be used to filter the data on that sheet to allow populating the listboxes.

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

    Re: Combobox and two listBoxes

    See if this is how you wanted
    Added CommandButton x 1
    Please Login or Register  to view this content.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    Arigatou gozaimasu Jindon It is working super fine One more thing I would like to do is, when you click on an item in a listBox 2, get only maching values for that selected item in ListBox 3. Is it possible?

    Thank you again.

    Yukiko.

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

    Re: Combobox and two listBoxes

    Try this. Double click on item in Listbox2 to see result in ListBox3.
    Please Login or Register  to view this content.
    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.

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

    Re: Combobox and two listBoxes

    Quote Originally Posted by Yokosuka View Post
    Arigatou gozaimasu Jindon It is working super fine One more thing I would like to do is, when you click on an item in a listBox 2, get only maching values for that selected item in ListBox 3. Is it possible?

    Thank you again.

    Yukiko.
    Can not use Click event since ListBox2 is multiselect. So DoubleClick on ListBox2.
    Change to
    Please Login or Register  to view this content.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    Thank you so much guys you are awesome. Thank you so much Jindon. I am trying to understand your code therefore, I would like to add a listbox 4 changed by listbox3 with the same principle I added lisbox3 change and listbox3_DbClick blocks but it doens't work. I copy paste some values in column D to be assigned to listBox4.

    when I double click on an item in listbox 3 to get its values in Listbox 4 I got a run time '381' error (Could not get the list property. Invalid property array index.)

    So it means that did not understand the code well. is it related to . compareMode? should it be 2 to be able to add a second scripting dictionary? I am trying to understand. Thank you again for your efforts to help me.
    Yuki

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

    Re: Combobox and two listBoxes

    I don't understand what you are trying to do and what you did... So too hard to comment.

  11. #11
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    This is what I have added to your code: (I already declared d and dif as objects)

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    what I understood is .compareMode= number of column. I am just trying to understand, so if you can help me I will be thankful. Sorry if I disturbed you Jindon.
    Last edited by Yokosuka; 08-18-2016 at 09:31 AM.

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

    Re: Combobox and two listBoxes

    1) my original code has 3 lines that should be deleted. (still no harm without deletion)
    Please Login or Register  to view this content.
    2) There is no 3 for dictionary compareMode, only 1(textcompare) or 0(binarycomapre, defalt).

  13. #13
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    Understood Jindon.Thank you so much. when I add this code it show error 424: Object required.

    Please Login or Register  to view this content.

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

    Re: Combobox and two listBoxes

    Too difficult for me to comment.

    LB3_change
    Please Login or Register  to view this content.
    But LB_Dclick
    Please Login or Register  to view this content.
    Nee to see whole code, not just the part.

  15. #15
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    this is the code:
    Please Login or Register  to view this content.
    I added this line to combobox1_change, but now I got value from column D in LB3.
    Please Login or Register  to view this content.

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

    Re: Combobox and two listBoxes

    1) Does it compile in the first place?

    2) What are you trying to do with the red line?
    Please Login or Register  to view this content.
    3) What would be the reason for b declared as global variable?
    Please Login or Register  to view this content.

  17. #17
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    No answer Have a wonderful weekend.

  18. #18
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    Sorry Jindon I have not seen your last message, it was in the second page. Please excuse my ignorance.

    To be able to add a listbox 4 May be I need to do same approach but using the global variable b instead of a?

    This variable b was actually initially in the code provided by you. I was asking myself why is b declared but it doesn't figure in the code.

    The red line was actually a comment. I am having a bad time with this, it is very hard for me. If I can do it for listbox 3 and listbox 4 exactly as you did it for LB2 and LB3, i can add more columns and therefore more listboxes.

    Thank you Jindon for the help and sorry again.
    Last edited by Yokosuka; 08-22-2016 at 04:54 PM.

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

    Re: Combobox and two listBoxes

    This variable b was actually initially in the code provided by you
    1) I can not find variable "b" in any of my codes...

    2) You said
    I am tired of trying to do it but I am not able to get the results since I lack of knowledge. I want to populate a combo box and two listboxes with unique values+ visible cells only.
    I thought you would filter the range first.

    Are we talking about the same issue?

  20. #20
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    Hello Jindon,

    Sorry about that. the b was on the excel sheet. I think i am the one who added it. You copy paste the data on the same sheet from K1. I don't want to copy paste on the same sheet but on a different one. Since I failed to do so, I commented that line.

  21. #21
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    I attached the excel file. It would much easy to show what I need to do. Sorry for not being clear from the beginning. I thought it would be easy to add the columns I want if I know how to do ot with two columns. But it is not that easy.

    Than you so much.
    Attached Files Attached Files

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

    Re: Combobox and two listBoxes

    Is this how you wanted?
    Please Login or Register  to view this content.

  23. #23
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    hello Jindon,

    Thank you for your efforts and help. I was trying to solve a problem again. When I execute the code, it shows " Run time Error 10004" Unable to get the CurrentRegion property of the range class" .

    I do not know what does it mean.

    thanks Jindon.

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

    Re: Combobox and two listBoxes

    If you are talking about files that have different sheet layouts, no idea.
    Correction:
    Please Login or Register  to view this content.
    Attached Files Attached Files

  25. #25
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    I rated this thread as excellent and marked it as resolved. You are awesome guys especially Jindon. Thank you for the help.

    Enjoy your weekend.

    Yuki

  26. #26
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    Hi Jindon,

    I deeply apologize for disturbing, but i just figured out that for listbox4, the filtering is done based only on listbox 3. I want to filter values in listbox4 based on listbox 3 and listbox 2 selection. Please Jindon support me.

    Yukiko

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

    Re: Combobox and two listBoxes

    It should be filtered from Combo1, List2 and List4.

  28. #28
    Registered User
    Join Date
    08-06-2016
    Location
    helsinki
    MS-Off Ver
    2010
    Posts
    37

    Re: Combobox and two listBoxes

    This is my last requirement. You really helped me a lot. If you can help me for the last time with the following:

    Actually your code is amazing and working fine. But when I double click on listbox3, I want to show results in listbox4 filtered according to what is selected in listbox 2 and listbox 3. This is my last quiry, I promesse.

    I cannot thank you enough.

    Yuki
    Last edited by Yokosuka; 09-07-2016 at 11:53 AM.

+ 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. Listboxes are populated by one Combobox selection
    By ttd in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-29-2014, 09:57 PM
  2. From one into 4 listboxes
    By jrkraucher in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-24-2013, 01:58 PM
  3. Need help with Listboxes!
    By Angelus in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-24-2006, 12:50 AM
  4. listboxes
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-30-2005, 02:06 PM
  5. [SOLVED] listboxes
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 02-22-2005, 12:06 PM
  6. listboxes
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-22-2005, 07:06 AM

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