Four column VBA combo box?

scoha

Active Member
Joined
Jun 15, 2005
Messages
428
I am new to VBA combo boxes so please be gentle!

I want a combo box that presents four columns of info per row (A, C,D & E) and then the value in Column A is retained for use in other macros.

From other posts I have got my combo box (cboProj) set up with a list filling routine in the from_initialize event.

Along the lines of :
Code:
Dim cProj as Range
Dim ws as Worksheet
Set ws = Worksheets ("WorksheetName1")

For each cProj in ws.Range("LookupRangeName")
With me.cboProj
.AddItem cProj.Value
.List(.ListCount-1,1)=cProj.Offset(0,1).Value
End With
Next cProj
Me.cbo.Proj.SetFocus

but this only shows two columns of info - whats the trick?
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Set the columncount to 4, boundcolumn to 1, and if your LookupRangeName range is only one column, use:
Code:
me.cboProj.List = ws.Range("LookupRangeName").Resize(,4).Value
 
Upvote 0
Thanks rorya

where would I place that line in my code sample? I am getting two columns currently - but I dont understand why as yet
 
Upvote 0
Current version:
Rich (BB code):
Dim cProj as Range
Dim ws as Worksheet
Set ws = Worksheets ("WorksheetName1")
 
For each cProj in ws.Range("LookupRangeName")
With me.cboProj
' adds item and populates bound column
.AddItem cProj.Value
' populates column 2
.List(.ListCount-1,1)=cProj.Offset(0,1).Value
' no code to populate more columns so that's all you get!
End With
Next cProj
Me.cbo.Proj.SetFocus

My version:
Rich (BB code):
Dim cProj as Range
Dim ws as Worksheet
Set ws = Worksheets ("WorksheetName1")
 
me.cboProj.List = ws.Range("LookupRangeName").Resize(,4).Value
Me.cbo.Proj.SetFocus
 
Upvote 0
To skip the second column, you can set the .ColumnWidths to 0

Code:
With Me
    With .ListBox1
        .ColumnCount = 5
        .BoundColumn = 1
        .List = Range("LookupRangeName").Resize(, 5).Value
        .ColumnWidths = ";0;;;"
    End With
End With
 
Upvote 0
Thanks rorya and mickerikson
It works and I now know a little more about combo boxes!

cheers
 
Upvote 0

Forum statistics

Threads
1,214,788
Messages
6,121,588
Members
449,039
Latest member
Arbind kumar

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top