populate combo box

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to populate a combo box on a userform. I need the combobox to have
two columns and for the columns to take their information from a worksheet.
The problem is that the two columns of information are not beside each other
so I cant get it to work. Can anyone hep?
 
Maybe something like this will help:

Option Explicit
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub CommandButton2_Click()
With Me.ComboBox1
If .ListIndex > -1 Then
MsgBox .List(.ListIndex, 0) & vbLf & .List(.ListIndex, 1)
End If
End With
End Sub
Private Sub UserForm_Initialize()
Dim myRng As Range
Dim myCell As Range

With Worksheets("sheet1")
Set myRng = .Range("a1", .Cells(.Rows.Count, "A").End(xlUp))
End With

With Me.ComboBox1
.ColumnCount = 2
For Each myCell In myRng.Cells
.AddItem myCell.Value
.List(.ListCount - 1, 1) = myCell.Offset(0, 2).Value
Next myCell
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top