Add Items To ComboBox

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Add Items To ComboBox

Post by jstevens »

I'm receiving an error message "Permissions Denied" when I use the following code to populate a "combobox". Any ideas as to why?

Code: Select all

Sub Add_Items_To_ComboBox_Array()
UserForm1.ComboBox1.SetFocus

For i = 1 To 7
    UserForm1.ComboBox1.AddItem Sheets("Sheet1").Range("K" & i).Value
Next i

End Sub
Thanks,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Add Items To ComboBox

Post by HansV »

Where are you calling this code?
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Add Items To ComboBox

Post by jstevens »

Hans,

From:

Code: Select all

Private Sub CheckBox1_Click()
    UserForm1.ComboBox1.Visible = True
        Add_Items_To_ComboBox_Array
End Sub
Regards,
John
Regards,
John

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Add Items To ComboBox

Post by HansV »

Hmm, I can't reproduce the error. Could you attach (a stripped down copy of) the workbook? Thanks in advance.
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Add Items To ComboBox

Post by jstevens »

Hans,

Please find attached a sample workbook as requested.

Regards,
John
You do not have the required permissions to view the files attached to this post.
Regards,
John

User avatar
HansV
Administrator
Posts: 78524
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Add Items To ComboBox

Post by HansV »

The reason for the error is that you have set the RowSource property of the combo box. If the RowSource of a list box or combo box is not blank, you can't use the AddItem or RemoveItem methods.
So if you clear the RowSource property of the combo box, the code should work as intended.
Best wishes,
Hans

jstevens
GoldLounger
Posts: 2631
Joined: 26 Jan 2010, 16:31
Location: Southern California

Re: Add Items To ComboBox

Post by jstevens »

Hans,

Thank you.

John
Regards,
John