+ Reply to Thread
Results 1 to 9 of 9

How to load a one-item list to a ComboBox

  1. #1
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    How to load a one-item list to a ComboBox

    Hi,

    I am trying to add a range of items to a combobox on a userform and the macro works fine except when the range is only one cell (ie one item long).

    How do I make the macro accommodate a list that can be one item long? Or even zero items (which of course would tell the use that no items are available to choose from).

    Here is my code now:

    Please Login or Register  to view this content.
    Thanks,

    Lawrence
    Last edited by skysurfer; 09-14-2010 at 03:21 AM.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: How to load a one-item list to a ComboBox

    How do you define the named range "NamesAll"?

    Can you post a workbook?

    Regards

  3. #3
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: How to load a one-item list to a ComboBox

    Hello skysurfer,

    Here is one way to do it...
    Please Login or Register  to view this content.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  4. #4
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: How to load a one-item list to a ComboBox

    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  5. #5
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How to load a one-item list to a ComboBox

    Thanks for the replies!

    Two issues: First, the "Add" method (in Case 1) in Leith's macro blows up. I get the error message "Method or data member not found". Also, no matter how many names there are, Case 1 is always selected. Weird.

    The range name NamesAll is the following formula:

    =Database01!$C$16:INDEX(Database01!$16:$16,1,COUNTA(Database01!$16:$16))

    Lawrence

  6. #6
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How to load a one-item list to a ComboBox

    Hold it...

    Found the problem. "Add" should be "AddItem".

    On a related issue, the formula for the range name (see prior posting) has one nasty little bug: I can't handle a range count of zero. Any though on how that should work? I've been trying to replace all the OFFSETs with INDEX, but this one bug I haven't been able to overcome and it forces me to make complicated work-arounds like I need to use in the CASE SELECT.

    Thanks,

    Lawrence

  7. #7
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: How to load a one-item list to a ComboBox

    What do you want to happen if the range is completely blank?

  8. #8
    Forum Contributor
    Join Date
    05-24-2006
    Location
    Los Angeles
    MS-Off Ver
    2019
    Posts
    328

    Re: How to load a one-item list to a ComboBox

    romperstomper,

    Result in a zero or null value. Right now, if I use the basic INDEX formula structure posted below and add the COLUMNS function to it, it will result in the number 2 when the range is empty.

    BTW, thanks for your first replay...it helped solve why the macro no worky.

    Lawrence

  9. #9
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: How to load a one-item list to a ComboBox

    Something like:
    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