Problem with Populating a Userform Combo Box with a Dynamic Range

Zabman

Board Regular
Joined
Apr 7, 2010
Messages
77
Hi,

I am trying to create a combobox within a userform that pulls its items from a dynamic range called "Options_Port" "=OFFSET(Options!$B$9,0,0,COUNTA(Options!$B11:$B103),1" on a worksheet called "Options". I am not sure if it matters, but the worksheet "Options" is hidden.

I have verified the range is correct and definately pulling up data.

When I try to run the following code, I get a Run-time error '1004': Method 'Range' of object '__Global' failed.

I have also tried explicitly naming the range by calling it from ActiveWorkbook etc, but I still get the same error. Please help!

Code:
Private Sub UserForm_Initialize()
    PortSelect.List = Range("Options_Port").Value
End Sub
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
See if either of these work. Make sure the combobox's RowSource property is cleared. The 12 is a constant for visible cells.


Code:
Private Sub UserForm_Initialize()
PortSelect.List = Range("Options_Port").SpecialCells(12).Value
End Sub

or

Code:
Private Sub UserForm_Initialize()
Dim cell as Range
For each cell in sheets("Options").Range("B11:B103").SpecialCells(12)
PortSelect.AddItem cell.Value
Next cell
End Sub

or

Code:
Private Sub UserForm_Initialize()
Dim cell as Range
For each cell in sheets("Options").Range("B11:B103")
If len(cell.Value) > 0 Then PortSelect.AddItem cell.Value
Next cell
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,583
Messages
6,125,665
Members
449,247
Latest member
wingedshoes

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