+ Reply to Thread
Results 1 to 7 of 7

Add same list in multiple comboboxes

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Add same list in multiple comboboxes

    Hi guys
    I have written the following code but its giving me runtime error "Object required".

    ANy help would be much appreciated.

    Private Sub UserForm_Initialize()
    loadcombos (ComboBox2)
    loadcombos (ComboBox3)
    loadcombos (ComboBox4)
    loadcombos (ComboBox5)
       
    End Sub
    
    Public Sub loadcombos(a As ComboBox)
    a.AddItem "Late post"
    a.AddItem "High volume"
    a.AddItem "Work flow"
    a.AddItem "Staffing issue"
    a.AddItem "Support elsewhere"
    End Sub
    Last edited by aman1234; 06-07-2011 at 06:53 AM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Add same list in multiple comboboxes

    Do not use 'additem' to populate a combobox/listbox, but use 'List' instead.

    Private Sub UserForm_Initialize()
      for j=2 to 5
        Me("combobox" & j).list=split("Late post|High volume|Work flow|Staffing issue|Support elsewhere","|")
      next
    End Sub



  3. #3
    Valued Forum Contributor mohd9876's Avatar
    Join Date
    05-04-2011
    Location
    Amman, Jordan
    MS-Off Ver
    Excel 2010
    Posts
    426

    Re: Add same list in multiple comboboxes

    remove the parantheses
    Private Sub UserForm_Initialize()
    loadcombos ComboBox2
    loadcombos ComboBox3
    loadcombos ComboBox4
    loadcombos ComboBox5
       
    End Sub

  4. #4
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Add same list in multiple comboboxes

    it doesnt know which object/userform
    Sub UserForm_Initialize()
    loadcombos Me.ComboBox2
    loadcombos Me.ComboBox3
    loadcombos Me.ComboBox4
    loadcombos Me.ComboBox5
       
    End Sub
    
     Sub loadcombos(a As ComboBox)
    With a
    .AddItem "Late post"
    .AddItem "High volume"
    .AddItem "Work flow"
    .AddItem "Staffing issue"
    .AddItem "Support elsewhere"
    End With
    End Sub
    If the solution helped please donate to RSPCA

    Site worth visiting: Rabbitohs

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

    Re: Add same list in multiple comboboxes

    Try this

    Private Sub UserForm_Initialize()
    Dim iX As Integer
    For iX = 2 To 5
    Me("ComboBox" & iX).List = Array("Late post", "High volume", "Work flow", _
        "Staffing issue", "Support elsewhere")
    Next iX
    End Sub
    Last edited by royUK; 06-07-2011 at 05:13 AM.
    Hope that helps.

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

    Free DataBaseForm example

  6. #6
    Forum Contributor
    Join Date
    02-20-2009
    Location
    bristol
    MS-Off Ver
    Excel 2003
    Posts
    882

    Re: Add same list in multiple comboboxes

    Thanks guys for your help. All methods worked well. This is the first time I used split and array function and it works a treat.

  7. #7
    Forum Expert pike's Avatar
    Join Date
    12-11-2005
    Location
    Alstonville, Australia
    MS-Off Ver
    2016
    Posts
    5,342

    Re: Add same list in multiple comboboxes

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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