+ Reply to Thread
Results 1 to 11 of 11

Add two Named Ranges in one ComboBox control

  1. #1
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Add two Named Ranges in one ComboBox control

    Dear All,

    I hope you are all well.

    I have two NamedRanges that are lists of different departments.

    What I need, is to have a ComboBox with both NamedRanges merged on the Drop Down list.

    The code I have, it lists one of the named ranges and hides the cells market as "Empty" as follow:

    Please Login or Register  to view this content.
    As you can see, one of the named ranges is "DU" and I need to add another into the list (named range as "FU").

    Is it possible to "merge" it into one ComboBox?

    Your assistance on this matter will be highly appreciated.

    Best regards,
    Filipe

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,751

    Re: Add two Named Ranges in one ComboBox control

    You can repeat the technique you used for DU:


    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert MickG's Avatar
    Join Date
    11-23-2007
    Location
    Banbury,Oxfordshire
    Posts
    2,650

    Re: Add two Named Ranges in one ComboBox control

    Try this:-
    Please Login or Register  to view this content.

  4. #4
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Add two Named Ranges in one ComboBox control

    With two different ranges, presumably separate, you might want to add a hidden column to the combo box so you can tell where the data came from

    Please Login or Register  to view this content.
    Also, I'm wondering about this being in the DropButtonClick event. In the Userform_Intialize event is usually where one loads a combo box. If the dropbuttonClick is where it needs to go, there should be a line clearing the combo box before it is filled (or double filled),
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  5. #5
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Add two Named Ranges in one ComboBox control

    Thanks guys,

    It worked perfectly.

    I have used the reply from 6StringJazzer as it was the first reply and it worked as desired.

    I will keep the other tips for the future.

    Once again, thanks a million for your precious help. Really appreciated.

    Filipe Oliveira.

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,751

    Re: Add two Named Ranges in one ComboBox control

    Actually, here is one more that is a more elegant than my initial. However, I won't blame you if you quit while you're ahead :-)

    <to avoid confusion, removed code containing one error and one possibly incorrect assumption>
    Last edited by 6StringJazzer; 01-23-2015 at 11:03 PM.

  7. #7
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: Add two Named Ranges in one ComboBox control

    Combining the names inside one statement will error if the named ranges are on different sheets.
    Also, the .Columns property of a discontinuous range acts oddly for Excel 2013.
    The loop omits the cells in the second Area of the combined range.
    Please Login or Register  to view this content.

  8. #8
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,751

    Re: Add two Named Ranges in one ComboBox control

    Quote Originally Posted by mikerickson View Post
    Combining the names inside one statement will error if the named ranges are on different sheets.
    Also, the .Columns property of a discontinuous range acts oddly for Excel 2013.
    The loop omits the cells in the second Area of the combined range.
    True on both counts. I had not done any significant testing (OP should attach a file).

    On the second point, this is not specific to 2013. The Columns(1) will select the first column of the entire range, not each named range individually. Therefore only the leftmost column of the entire combined range is used.

    Therefore I retract my second suggestion.

  9. #9
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Add two Named Ranges in one ComboBox control

    Thanks guys.

    @6StringJazzer, I have tried initially to add the two names ranges as "With Range("DU, FU")" but it didn't worked.

    Although it is working well now, I am facing a small issue. Not sure If I do have to create a new threat for it.

    Now, if I click the drop down menu, close and open again, it keeps adding and duplicating the values on the ComboBox menu.

    Any ideas? As I mention, maybe I need to create a new threat.

    Thanks a million in advance.

    Kind regards,
    Filipe

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,751

    Re: Add two Named Ranges in one ComboBox control

    In in the posts above you will see that if DU and FU are on different sheets, my second solution won't work, and I have removed it. Stick with the first one, or other solutions presented here as you prefer.

    To solve your latest problem add this line before the first With statement:

    Please Login or Register  to view this content.
    Do the values in DU and FU change? If they never change, then you should load the combobox in the UserForm_Activate sub, rather than doing it every time the user clicks on the combobox.

  11. #11
    Forum Contributor pipoliveira's Avatar
    Join Date
    08-09-2012
    Location
    Ireland
    MS-Off Ver
    Microsoft Office 365 ProPlus
    Posts
    368

    Re: Add two Named Ranges in one ComboBox control

    That's it! It solved the problem.
    You're a star. Very appreciated.
    Best regards,
    Filipe


    Sent from my iPhone using Tapatalk


    * If a reply solved or answered your query/question, you can add reputation to the person by clicking on the * Add Reputation
    * When question is resolved, please mark your thread as SOLVED


    Thanks and regards,
    Filipe Oliveira

+ 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. Define only 2 named ranges from a list of named ranges...
    By abhi900 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 04-29-2014, 04:20 AM
  2. Combobox with named ranges values to Textboxes
    By Kburges in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-21-2013, 12:42 PM
  3. [SOLVED] Named ranges and combobox
    By bigfoot007 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-17-2012, 03:06 PM
  4. User Defined Functions: can control what named ranges get used?
    By djt76010 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-21-2008, 08:26 PM
  5. Indirect with Named ranges - Control cell
    By danxt in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 04-23-2007, 11:40 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