+ Reply to Thread
Results 1 to 5 of 5

Initialize event to populate two Comboboxes?

Hybrid View

  1. #1
    Registered User
    Join Date
    05-29-2010
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    27

    Initialize event to populate two Comboboxes?

    Hi, i have the following code that populates one Combobox which is fine. However, i seem to be unable to populate a second combobox (Combobox2) that pulls its values form range B. Couls somebody help to amend? Thank you very much!
    Sub UserForm_Initialize()
    Dim lstRng As Range
        Set lstRng = Sheet1.Range("A2:J2", Range("A65536").End(xlUp))
        Me.Combobox1.RowSource = lstRng.Address
    End Sub
    Last edited by fcb1900; 11-21-2010 at 05:02 PM.

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,523

    Re: Initialize event to populate two Comboboxes?

    Can you not set a 2ndRng and do the same thing as you did for combobox1?

  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,259

    Re: Initialize event to populate two Comboboxes?

    Hello fcb1900,

    If the values are all in column "B" of "Sheet1" then this will work.
    Sub UserForm_Initialize()
    Dim lstRng As Range
        Set lstRng = Sheet1.Range("A2:J2", Range("A65536").End(xlUp))
        Me.Combobox1.RowSource = lstRng.Address
    
        Set lstRng = Sheet1.Range("B2:B" & Sheet1.Cells(Rows.Count, "B").End(xlUp).Row)
        ComboBox2.RowSource = lstRng.Address
    End Sub
    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 Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Initialize event to populate two Comboboxes?

    Sub UserForm_Initialize()
      Combobox1.List= Sheet1.Range("A2:J2").Resize(Sheet1.cells(.rows.count,1).end(xlup).row-1).value
      Combobox2.list=combobox1.List
    End Sub



  5. #5
    Registered User
    Join Date
    05-29-2010
    Location
    Greece
    MS-Off Ver
    Excel 2007
    Posts
    27

    Re: Initialize event to populate two Comboboxes?

    Thanks Leith and snb, both solutions work fine!

+ 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