+ Reply to Thread
Results 1 to 16 of 16

How can I get my combobox list to fill with a range without using rowsource property?

  1. #1
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    How can I get my combobox list to fill with a range without using rowsource property?

    Hello again,
    This is question 2 of 3. The 1st was solved by bakerman2...a BIG thanks to him for his help.
    In the attached I have a simple userform with 3 comboboxes. I am currently using the RowSource property for the comboboxes to fill them with the proper list. What I would like to do is go through Column A in the Lists sheet and fill in combobox1 with the cells that are not blank starting in row 2. Also, if the user types something that is not in the list, add it to the column.


    BTV Excel Forum Sample.xlsm
    1N73LL1G3NC3 15 7H3 4B1L17Y 70 4D4P7 70 CH4NG3 - 573PH3N H4WK1NG
    You don't have to add Rep if I have helped you out (but it would be nice), but please mark the thread as SOLVED if your issue is resolved.

    Tom

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

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

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    If you insert a blank column between A & B and B & C then you could use this.

    Please Login or Register  to view this content.
    PS Don't forget to remove RowSource from Combo's before running the code.
    Last edited by bakerman2; 10-17-2017 at 03:07 PM. Reason: Corrected code
    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
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    Thanks to both of you for your code!. Each of the codes you guys provided did populate the lists like I wanted, but, neither one of them will add to the list in the sheet lists if a user hand keys into the combobox and it doesn't exist on the list already.

    @bakerman2 - What is the purpose of inserting the blank columns? I tried it without and with and the only difference I noticed is that it added a lot of empty space at the end of the list of the comboboxes when I didn't insert a blank column as opposed to only having 1 empty space with the blank columns inserted. I'm guessing this is the reason for the inserted blank columns, to eliminate most of the empty space.
    With AlphaFrog's code, there was no empty space at the end of the lists.

    Edit* I forgot to ask this in my original post. Since I'm allowing user input to be added to the list(s), is there a way to auto sort those lists from A to Z when a new item is added?
    Last edited by gmr4evr1; 10-17-2017 at 02:24 PM.

  5. #5
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    Quote Originally Posted by gmr4evr1 View Post
    Thanks to both of you for your code!. Each of the codes you guys provided did populate the lists like I wanted, but, neither one of them will add to the list in the sheet lists if a user hand keys into the combobox and it doesn't exist on the list already.

    @bakerman2 - What is the purpose of inserting the blank columns? I tried it without and with and the only difference I noticed is that it added a lot of empty space at the end of the list of the comboboxes when I didn't insert a blank column as opposed to only having 1 empty space with the blank columns inserted. I'm guessing this is the reason for the inserted blank columns, to eliminate most of the empty space.
    With AlphaFrog's code, there was no empty space at the end of the lists.

    Edit* I forgot to ask this in my original post. Since I'm allowing user input to be added to the list(s), is there a way to auto sort those lists from A to Z when a new item is added?

    If the user adds to the lists before they load the userform, the comboboxes will include the new items when the userform loads.

    If you want them to be able to add to the lists while the userform is already loaded, then make a command button to update the lists and use the same code I gave before for the command button.

    You can record a macro where you sort the lists and then copy that code to your existing code.
    Last edited by AlphaFrog; 10-17-2017 at 03:08 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,914

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    This is the corrected code. My apopolgies for posting wrong code.

    The reason you insert a column between is that CurrentRegion takes all adjacent columns and rows so defining the range for each combobox would take more code than now.

    Please Login or Register  to view this content.

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

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    Here's code to ask the user if they want to add a new item if they enter an item not on the list.

    It's for ComboBox1 but the same idea could be applied to the others.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  8. #8
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    @ AlphaFrog - The userform will be initialized when the workbook opens. I had code once before that would allow a user to type into the combobox and if what they typed wasn't already on the list, it would add it to the list from the combobox, the problem is, I cannot find where I saved the code to do this.

    @bakerman2 - The code you provided in post # 6 is the same as the code in post #3...isn't it? Or am I missing something.

    @Norie - If I can't find the code I had before to add to the list, or if what I'm asking isn't possible, I will use the code you provided.

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

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    It's indeed the same as in post#3 but I corrected that one too just for clarity (Previous code all lines said Combobox1)
    This code checks for Combobox1 but can be adapted for the other 2.

    Please Login or Register  to view this content.
    Edit: Have added the code for all 3 CB's. Just fill with 3 non-existing values and click Submit-button.
    Attached Files Attached Files
    Last edited by bakerman2; 10-17-2017 at 05:52 PM. Reason: Added example file

  10. #10
    Forum Expert
    Join Date
    12-14-2012
    Location
    London England
    MS-Off Ver
    MS 365 Office Suite.
    Posts
    8,448

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    Sorry Guys

    I do not see how the above solutions get rid of the blank entries in the Comboboxes.

    This solution loads comboboxes 1 to 3 with the data in columns A to C without any blanks.

    Please Login or Register  to view this content.
    My General Rules if you want my help. Not aimed at any person in particular:

    1. Please Make Requests not demands, none of us get paid here.

    2. Check back on your post regularly. I will not return to a post after 4 days.
    If it is not important to you then it definitely is not important to me.

  11. #11
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    Sorry everyone, it took me a while to be able to get bake to this and after some testing I've found a few issues.

    Bakerman2 - After some discussion with the end users we determined that the only column we needed the list to update for was C on the Lists sheet. I've modified your code to reflect this but I have run into a problem. It seems to add items to the list that DO exist on the list already, as well as items that don't exist. On Sheet1, row 16 after I typed New into combobox3 of the userform and clicked submit, it added New to the list in column C of the List sheet as it should have (see C12 on the Lists sheet). I then ran the workbook open code again and selected New from combobox3 then clicked submit on the userform and New was added to column C of the List sheet a 2nd time (see C13 on the Lists sheet) I'm not sure why it is adding already existing items to the list.
    Bakerman2 BTV Excel Forum Sample.xlsm

    Norie - The code you provided worked great and I am considering using it for this application. Even if it's not used for this one, it will be used in future ones. Thank you very much.

    Mehmetcik - I tried the code you provided and was not able to get it to work. With Option Explicit being used, it would error at the For Count line (with Count highlighted) with a Compile error: Variable not defined. I removed Option Explicit and would get this error - Compile error: Method or data member not found on the
    Please Login or Register  to view this content.
    with .Controls highlighted.
    mehmetcik BTV Excel Forum Sample.xlsm
    Last edited by gmr4evr1; 11-05-2017 at 12:52 AM. Reason: Corrected typos

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

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    Please Login or Register  to view this content.

  13. #13
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    bakerman2,
    That did it!! Thank you [all] so much for your help!!

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

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    Glad to help and up to question 3 now ?

  15. #15
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    And I'm glad you offered to help.
    I will be posting that thread (3) later today or tomorrow.

  16. #16
    Forum Expert gmr4evr1's Avatar
    Join Date
    11-24-2014
    Location
    Texas
    MS-Off Ver
    Office 2010 and 2007
    Posts
    3,448

    Re: How can I get my combobox list to fill with a range without using rowsource property?

    While searching for the code for question 3 posted here
    https://www.excelforum.com/excel-pro...ml#post4780713
    I found the code that I was originally looking for when I asked the question in this post "How can I get my combobox list to fill with a range without using rowsource property?", which is question 2 of 3.
    Here is the code, modified to suit my needs...
    Please Login or Register  to view this content.
    Here's the kicker....I'm the one that provided the above code for another member in this post..it's post #2
    https://www.excelforum.com/excel-pro...-userform.html

+ 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. UserForm -> Combobox and it's RowSource property?
    By CEC in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-02-2013, 02:16 PM
  2. Selecting an Item in a ComboBox with a List Created from RowSource
    By shona_jk in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 01-09-2013, 07:44 AM
  3. [SOLVED] Set RowSource for Combobox with Range Name
    By anandvh in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-03-2012, 11:21 AM
  4. setting a combobox list property to a named range
    By matpj in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-06-2012, 11:52 AM
  5. Combobox Rowsource Dynamic Range
    By roy__lam in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-06-2012, 09:44 AM
  6. Different results for ComboBox.RowSource property in BeforeUpdate Event
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-28-2010, 01:07 PM
  7. Rowsource property error in combobox userform
    By asha3010 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-15-2010, 08:06 AM
  8. [SOLVED] How do I set the rowsource for a ComboBox for a dynamic list?
    By ndm berry in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-29-2005, 09:05 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