Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Fill a combobox with a named range

  1. #1
    New Member
    Join Date
    Jan 2010
    Posts
    18
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Fill a combobox with a named range

    Hi,

    This is a very basic question, but i have been struggling for hours, so I must ask.

    I I trying to simply fill a combobox on a userform from a named range on a sheet, I want to populate the combobox as soon as the userform starts. (I launch the userform from a button on the sheet) Where must I place the code? and will this code work?
    Code:
    Sub Button1_Click()
    Set UserForm1.combobox1.List = Sheets("Sheet1").Range("MyRange")
    UserForm1.Show
    End Sub
    I am very new to vba, so please excuse my ignorance,
    any help would be greatly appreciated

    regards
    jim

  2. #2
    Board Regular
    The other chart guy
    Andy Pope's Avatar
    Join Date
    Dec 2003
    Location
    UK
    Posts
    346
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Fill a combobox with a named range

    I would place the code in the userforms Initialize event.
    In design mode double click the userform to code to the code window. Using the right hand Procedures dropdown to select the Initialize event.

    So assuming your named range was the cells A1:A5 on sheet1.

    Code:
    Private Sub UserForm_Initialize()
    
        ComboBox1.List = Application.WorksheetFunction.Transpose(ThisWorkbook.Names("MyRange").RefersToRange)
        
    End Sub
    Cheers
    Andy

  3. #3
    New Member
    Join Date
    Jan 2010
    Posts
    18
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Fill a combobox with a named range

    Andy you absolute legend!
    Thank you.

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •