Combobox Error When Using AddItem

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,616
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I have this code in my userform initialization code.

Rich (BB code):
...
With cbx_res
        .AddItem "8k (7680x4320)"
        .AddItem "4k (3840x2160)"
        .AddItem "2k (2560x1440)"
        .AddItem "HD2 (1920x1080)"
        .AddItem "HD1 (1280x720)"
        .AddItem "SD3 (854x480)"
        .AddItem "SD2 (640x360)"
        .AddItem "SD1 (426x240)"
    End With
...

I am getting a "Method or data member not found" error with the line and red (and those that follow similarly). "cbx_res is the combobox control's name.
I'm using Excel v2411 packaged in Micosoft 365.
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Is the combobox on a UserForm, or a worksheet? If it is on a worksheet, it is an ActiveX or Forms control? Did you double check the name?

If your combobox is a Forms control, that code won't work.
 
Upvote 0
Thanks Jeff,
It's a forms control wintin a userform. The control name is correct.
If your combobox is a Forms control, that code won't work.
What solution should I use to get what I need? It's likely an option to use rowsource and point it to a range in a worksheet, but I'm kinda hoping I don't need to dedicate a worksheet to a static list.
 
Upvote 0
does it work if you do it this way ?
VBA Code:
cbx_res.List = Array("8k (7680x4320)", "4k (3840x2160)", "2k (2560x1440)", "HD2 (1920x1080)", _
                     "HD1 (1280x720)", "SD3 (854x480)", "SD2 (640x360)", "SD1 (426x240)")
 
Upvote 0
If it's a ComboBox inside a UserForm, it should work with just .AddItem. Does it look like this?
1734714711551.png
 
Upvote 0
I set up a file with what you describe and it works for me. You must have an error in something that you are not showing us.

1734756616789.png


Code in UserForm module
VBA Code:
Option Explicit

Private Sub UserForm_Initialize()

   MsgBox "init"
   
   With cbx_res
      .AddItem "8k (7680x4320)"
      .AddItem "4k (3840x2160)"
      .AddItem "2k (2560x1440)"
      .AddItem "HD2 (1920x1080)"
      .AddItem "HD1 (1280x720)"
      .AddItem "SD3 (854x480)"
      .AddItem "SD2 (640x360)"
      .AddItem "SD1 (426x240)"
   End With

End Sub


Private Sub CommandButtonClose_Click()
   Unload Me
End Sub

Code in standard module to open form
VBA Code:
Sub runform()
   UserFormArk68.Show
   MsgBox "Exit"
End Sub

Run the code and click the combobox for a dropdown
1734756739639.png
 
Upvote 0

Forum statistics

Threads
1,224,827
Messages
6,181,197
Members
453,021
Latest member
pingpong7117

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