Consulting

Results 1 to 4 of 4

Thread: Combobox on a form

  1. #1
    VBAX Mentor
    Joined
    Nov 2008
    Posts
    305
    Location

    Combobox on a form

    Excel 2000.

    I have a workbook that contains 1 worksheet ("Datalist") which has a named region "Equipment".
    Worksheet 2 ("Sheet2") containes a dropdownlist (Cell O3), which lists the items in Equipment.
    I have a form, which contains a combobox. When the form activates, I want it to default to show the data on sheet2 (Cell O3). BUT I want the combobox items to list the contents of "Equipment", on the Datalist sheet.
    How do I set these parameters?

    Cheers

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Without seeing anything

    [vba]

    Private Sub Userform_Activate()

    With Me.ComboBox1

    .List = Application.Transpose(Worksheets("Equipment").Range("A1:A10"))
    .ListIndex = Application.Match(Worksheets("Sheet2").Range("O3").Value, Worksheets("Equipment").Columns("A"), 0) - 1
    End With
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Mentor
    Joined
    Nov 2008
    Posts
    305
    Location
    The .ListIndex line isn't working. I'm getting a runtime error "9". Subscript out of range.

  4. #4
    Moderator VBAX Wizard lucas's Avatar
    Joined
    Jun 2004
    Location
    Tulsa, Oklahoma
    Posts
    7,323
    Location
    subscript out of range usually means it can't find something. Check the spelling of the sheet names on the tabs and in the code.

    post the workbook...
    Steve
    "Nearly all men can stand adversity, but if you want to test a man's character, give him power."
    -Abraham Lincoln

Posting Permissions

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