+ Reply to Thread
Results 1 to 4 of 4

Adding same items to more than one combo box

Hybrid View

  1. #1
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327

    Adding same items to more than one combo box

    Hi all,

    Great forum and I've had a good few answers to other posts I've made. Hope someone can help me with this one.

    I have a userform with two tabs on it and on each tab there are several comboboxes. In the UserForm_Initialize sub I populate each of these comboboxes with the following code:

    Sub UserForm_Initialize()
    With comPTcomposer
        .AddItem "Mary Jones"
        .AddItem "John Smith"
        .AddItem "Peter Wilson"
    End With
    These items need to populate a second combobox named comGPcomposer. So I then have another With statement adding the same items to it.

    My question is is there a way to add a list of items to an array of comboboxes something like:

    With Array(comPTcomposer, comGPcomposer)
        .AddItem "Mary Jones"
        .AddItem "John Smith"
        .AddItem "Peter Wilson"
    End With
    I tried the code above and got a RunTime Error 424 - Object required.

    I realise that this is not going to speed up the code at all but the Initialize Sub looks really messy with a lot of code repeated again and again

    Any help would be much appreciated.

    TIA

    Seamus

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    Do you really need duplicate comboboxes?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    You could use

    Private Sub UserForm_Initialize()
    With Me
    .ComboBox1.List = Array("Mary Jones", "John Smith", "Peter Wilson")
    .ComboBox2.List = Array("Mary Jones", "John Smith", "Peter Wilson")
    End With
    End Sub

  4. #4
    Forum Contributor SOS's Avatar
    Join Date
    01-26-2004
    Location
    Glasgow, Scotland
    MS-Off Ver
    Excel 2003
    Posts
    327
    royUK,

    Excellent - that did it. I do need duplicate comboboxes because I need the user to fill in either multipage 0 or 1 and then on clicking OK the values are inputted. I don't want them to have to choose one combobox from one tab and all the rest of the info from the other tab.

    Hope that makes sense.

    Seamus

+ 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