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

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,408
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
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

scoha

Active Member
Joined
Jun 15, 2005
Messages
428
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

RoryA

MrExcel MVP, Moderator
Joined
May 2, 2008
Messages
40,408
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
  2. MacOS
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

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
24,348
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

scoha

Active Member
Joined
Jun 15, 2005
Messages
428
Thanks rorya and mickerikson
It works and I now know a little more about combo boxes!

cheers
 
Upvote 0

Forum statistics

Threads
1,191,421
Messages
5,986,483
Members
440,031
Latest member
davidvillegasr

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
Top