populate combo box

E

enyaw

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?
 
D

Dave Peterson

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
 
Top