Combobox to Show 2 values in same row

C

Corey

I can get 2 columns to display in a Combobox,
but i am unable to work out how to populate the other value from code.

Currently i use this:

Private Sub ComboBox2_DropButtonClick()
Application.ScreenUpdating = False
If ComboBox2.ListCount > 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("to be Done").Cells(Rows.Count, "C").End(xlUp).Row
With ActiveWorkbook.Worksheets("to be Done")
..Select
For myrow = 1 To LastCell
If .Cells(myrow, 3) <> "" Then
ComboBox2.AddItem Cells(myrow, 3)
End If
Next
End With
Application.ScreenUpdating = True
End Sub

But i want to add to the Combobox a Column to display the value in Column A as well as Column C in it.

How do i do this the above ?

Corey....
 
M

Mike Fogleman

Corey, you will need to change your method of adding items from a loop to a ListFillRange if you want more than 1 column. The secret here is to set a 3-column combobox, but hide the 2nd column.

Private Sub ComboBox2_DropButtonClick()
Application.ScreenUpdating = False
'If ComboBox2.ListCount > 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("to be Done").Cells(Rows.Count, "C").End(xlUp).Row
With Me.ComboBox2
.ListFillRange = "A1:C" & LastCell
.ColumnCount = 3
.ColumnWidths = "90;0;90" 'hide col 2
.BoundColumn = 3 'sets .Value
.TextColumn = 3 'sets .Text
End With
Application.ScreenUpdating = True
End Sub

Mike F
I can get 2 columns to display in a Combobox,
but i am unable to work out how to populate the other value from code.

Currently i use this:

Private Sub ComboBox2_DropButtonClick()
Application.ScreenUpdating = False
If ComboBox2.ListCount > 0 Then Exit Sub
Dim LastCell As Long
Dim myrow As Long
On Error Resume Next
LastCell = Worksheets("to be Done").Cells(Rows.Count, "C").End(xlUp).Row
With ActiveWorkbook.Worksheets("to be Done")
.Select
For myrow = 1 To LastCell
If .Cells(myrow, 3) <> "" Then
ComboBox2.AddItem Cells(myrow, 3)
End If
Next
End With
Application.ScreenUpdating = True
End Sub

But i want to add to the Combobox a Column to display the value in Column A as well as Column C in it.

How do i do this the above ?

Corey....
 
M

merjet

After: ComboBox2.AddItem Cells(myrow, 3)
Insert: ComboBox2.Column(1, myrow - 1) = Cells(myrow, 1)
'Column is a 0 base array

Hth,
Merjet
 
C

Corey

perfect thanks
After: ComboBox2.AddItem Cells(myrow, 3)
Insert: ComboBox2.Column(1, myrow - 1) = Cells(myrow, 1)
'Column is a 0 base array

Hth,
Merjet
 

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

Top