Populate drop-down list based on column

Clarus Dignus

New Member
Joined
Apr 1, 2014
Messages
4
I'm trying to modify the following working code:

Code:
'Populate drop-down list (combo box) from range...
Dim range_b As Range

For Each range_b In Worksheets("2.1 Clients").Range("ClientList")
  With Me.cs_ClientName1
    .AddItem range_b.Value
    .List(.ListCount - 1, 1) = range_b.Offset(0, 1).Value
  End With
Next range_b

End Sub

Instead of using a named range, I need to target a column. I've tried changing this line:

Code:
For Each range_b In Worksheets("2.1 Clients").Range("ClientList")

...to this:

Code:
For Each range_b In Worksheets("2.1 Clients").Column(4)

...but I'm receiving an error (object doesn't support this property/method).

Any pointers on how I should select the column?
 
Last edited:

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Try this:
Rich (BB code):
Sub Populate()
  Const MyColumn = 4
  With Worksheets("2.1 Clients")
    Me.cs_ClientName1.List = .Range(.Cells(1, MyColumn), .Cells(.Rows.Count, MyColumn).End(xlUp)).Value
  End With
End Sub
 
Upvote 0
Thanks ZVI. I managed to get it working using the following code:

Code:
'Populate ClientName1 combo-box...

' Data Starts right below the Header (Named Range)
Set range_b = ThisWorkbook.Names("ClientList").RefersToRange.Offset(1, 0)
With Me.cs_ClientName1
    .Clear ' Clear existing data
    Do Until IsEmpty(range_b)
        .AddItem range_b.Value
        .List(.ListCount - 1, 1) = range_b.Offset(0, 1).Value
        Set range_b = range_b.Offset(1, 0)
    Loop
End With
Set range_b = Nothing

It requires that the header cell of the desired column be a named range (ClientList).
 
Upvote 0
Nice code, Clarus!
To speed it up you may also use this one:
Rich (BB code):
Sub Populate1()
  With ThisWorkbook.Names("ClientList").RefersToRange
     Me.cs_ClientName1.List = .Worksheet.Range(.Offset(1, 1), .Cells(Rows.Count  - .Row, 1).End(xlUp)).Value
  End With
End Sub
Best Regards
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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