Results 1 to 2 of 2

Thread: Populating userform combo boxes

  1. #1

    Populating userform combo boxes



    Register for a FREE account, and/
    or Log in to avoid these ads!

    Hi I'm having trouble populating a UserForm combo box

    Here's my code, any help would be great-

    Code:
    Private Sub ArchiveForm_Initialize()
    Dim cPart As Range
    Dim cLoc As Range
    Dim ws As Worksheet
    Set ws = Worksheets("Calibration Data")
    For Each cPart In ws.Range("Archives")
      With Me.ComboBox2
        .AddItem cPart.Value
        .List(.ListCount - 1, 1) = cLoc.Offset(0, 1).Value
      End With
    Next cPart
    For Each cLoc In ws.Range("Years")
      With Me.ComboBox1
        .AddItem cLoc.Value
        .List(.ListCount - 1, 1) = cLoc.Offset(0, 1).Value
      End With
    Next cLoc
    End Sub

  2. #2
    Administrator Ken Puls's Avatar
    Join Date
    Mar 2011
    Location
    Nanaimo, BC, Canada
    Posts
    2,250
    Articles
    57
    Blog Entries
    14
    Excel Version
    Excel Office 365 Insider
    Try this:


    Code:
    Private Sub UserForm_Initialize()Dim cPart As Range
    Dim cLoc As Range
    Dim ws As Worksheet
    Set ws = Worksheets("Calibration Data")
    For Each cPart In ws.Range("Archives")
      With Me.ComboBox2
        .AddItem cPart.Value
        .List(.ListCount - 1, 1) = cLoc.Offset(0, 1).Value
      End With
    Next cPart
    For Each cLoc In ws.Range("Years")
      With Me.ComboBox1
        .AddItem cLoc.Value
        .List(.ListCount - 1, 1) = cLoc.Offset(0, 1).Value
      End With
    Next cLoc
    End Sub
    Ken Puls, FCPA, FCMA, MS MVP (Excel)

    Learn to Master Your Data at the Power Query Academy (the world's most comprehensive online Power Query training) or with my book M is for Data Monkey!

    Main Site: http://www.excelguru.ca -||- Blog: http://www.excelguru.ca/blog -||- Forums: http://www.excelguru.ca/forums
    Check out the Excelguru Facebook Fan Page -||- Follow Me on Twitter

    If you've been given VBA code (a macro) for your solution, but don't know where to put it, CLICK HERE.

Posting Permissions

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