ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   populate combo box (https://www.excelbanter.com/excel-discussion-misc-queries/116175-populate-combo-box.html)

enyaw

populate combo box
 
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?

Dave Peterson

populate combo box
 
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




enyaw wrote:

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?


--

Dave Peterson


All times are GMT +1. The time now is 09:19 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com