+ Reply to Thread
Results 1 to 20 of 20

Userforms / Combobox

  1. #1
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Userforms / Combobox

    Ok, I'm building my first userform and have thrown in a combo box. I want to tie the options in the box to a list I have in my Excel sheet. Normally, if I wanted a drop down list I'd do the whole Data/Validation/List thing, but I'm not finding how to tie the two together in the VBA editor. I did a search and dug around in the results, but didn't find how to tie them together. Any helpful pointers in the right direction would be much appreciated!
    Thanks,
    Chad

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Userforms / Combobox - noob question.

    The combobox has a RowSource property which you can set at design or runtime.

    Please Login or Register  to view this content.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox - noob question.

    Excelent! Thank you Andy!

    C

  4. #4
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox

    Ok, so I put the code in (obviously using my sheet and cell refs) and when I run the form all I get is a blank box... it'll drop down but nothing is in it.

    ...and I also tried the other route and put "Sheet08!A198:213" in the comboboxes Row Source slot and got "Invalid Property Value".

    Is there an add in or something that I need to have turned on to get this to work or am I missing something?
    Much thanks!
    C

  5. #5
    Registered User
    Join Date
    12-28-2009
    Location
    USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Userforms / Combobox

    everytime i have used RowSource for a combobox I have used the following format and it has worked everytime so far.

    Sheet08!A198:A213

  6. #6
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox

    Sorry, I misstyped... I did have the extra "a" in there! We figured out that my problem is my computer. I had a coworker try on thier computer and the code worked fine and then I tried it on my laptop and it works fine there. Something is amiss on my work desktop!
    Thanks!
    Chad

  7. #7
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox

    Ok, I think I figured out what's going on.. apparently, you can not put the sheet reference in and have it work! I found that I had to make the worksheet that has my list active! This is the same if you're hard coding it in the combobox properties under "RowSource" So I ended up with the following code...

    Please Login or Register  to view this content.

    ...or if you're hard coding it into the combobox properties only put in the cell refs (ie - "A198:A213" without the quotes)

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Userforms / Combobox

    That's not the case for me.

    Userform uses contents of Sheet08. Works whether sheet is activesheet or not.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox

    Quote Originally Posted by Andy Pope View Post
    That's not the case for me.

    Userform uses contents of Sheet08. Works whether sheet is activesheet or not.
    Andy,
    Which version of Excel are you using? I'm using 2003 SP3.
    Chad

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Userforms / Combobox

    Same version xl03 SP3.

  11. #11
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox

    Interesting! It will not let me put the sheet name in there no matter what. When I try it gives me "Invalid Property Value" ...and this is whether I'm trying to use the sheet name proper or what I've renamed the tab. Odd.
    C

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Userforms / Combobox

    Maybe you should post your non working example.

    Have you checked the tab name and the text you use are the same. No spaces or extra characters?

  13. #13
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox

    Yes, I've checked and double checked all of that... Ok, I've attached a copy of the sheet where I've removed all of our proprietary math and it's still doing it.

    If I use..
    Please Login or Register  to view this content.
    ...I get a message box with, "Run time error '380': Could not set the RowSource property. Invalid property value." I can hit "OK" or "Help". OK ends the run and "Help" gives me a Excel help box with nothing in it.

    Now if I run...
    Please Login or Register  to view this content.
    ...it'll run fine, but it's pulling the list from Sheet1 instead of Sheet08.

    Maybe it's the zero I have in front of the 8 that's throwing something off?

    I opened a new excel sheet and copied your code in to the code editor once I'd made a fresh userform with a new combobox and it worked fine with the first code set.

    If you would, take a look when you have a chance and see if I'm doing anything blatantly wrong.
    Very much appreciated!
    Chad
    Attached Files Attached Files

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Userforms / Combobox

    You are using the Codename of the sheet rather than the Tab name

    Please Login or Register  to view this content.

  15. #15
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox

    BINGO! I think I just figured it out!

    The Tab name and the Sheet name have to be the same! If they are not, it doesn't work! ...and, it doesn't matter what the name is! Check me out on this.
    THX
    C

  16. #16
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Userforms / Combobox

    Not quite. The codename and tabname do not have to be the same.
    But you do have to use the tabname with that method.

  17. #17
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox

    Quote Originally Posted by Andy Pope View Post
    You are using the Codename of the sheet rather than the Tab name

    Please Login or Register  to view this content.
    You are correct! Scratch that last post by me!

    ..and I wasn't using the single quotes! Ok, I learned something new today. Thank you very much!
    Chad

  18. #18
    Forum Contributor
    Join Date
    05-20-2008
    Location
    England
    MS-Off Ver
    Office 365
    Posts
    176

    Re: Userforms / Combobox

    OK, this is a very similar problem to I have and I have tried copying your solutions into my project with no success at all.

    What am I doing wrong?

    I am using Excel 2007.
    Attached Files Attached Files

  19. #19
    Registered User
    Join Date
    11-16-2009
    Location
    Tucson, AZ
    MS-Off Ver
    Excel 2003
    Posts
    24

    Re: Userforms / Combobox

    I can't help you much since I'm stuck with 2003... sorry! Maybe someone with some 2007 experience can throw down.
    C

  20. #20
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,482

    Re: Userforms / Combobox

    Your post does not comply with Rule 2 of our Forum RULES. Don't post a question in the thread of another member -- start your own thread. If you feel it's particularly relevant, provide a link to the other thread.

    Your problem is that you created a routine with a name similar to the Initialize event but it is not the routine that is run when the form loads.

    Your routine
    Please Login or Register  to view this content.
    the Initialize event routine.
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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