Unable to pass a control to a sub

P

Paolo Sardi

I have the ListBox1 in a sheet (My Sheet), that is an embedded control. In
order to fill this listbox I call a sub located in Module1 that is something
like this:

Public Sub MySub (myListBox as ListBox)

myListBox.Clear
myListBox.AddItem ("John")
myListBox.AddItem ("Bill")
myListBox.AddItem ("Paul")

End Sub

When I call this sub from my sheet I call it like this:

Call MySub (Worksheets("My Sheet").ListBox1)

I get a Type-Mismatch error. I noticed that the listbox is Null and that the
same code works perfectly with a ComboBox instead of the ListBox.

Anyone knows I can I workaround this?
 
J

Jim Thomlinson

Public Sub MySub (myListBox as MSForms.ListBox)
or
Public Sub MySub (myListBox as Object)
This one is handy when you want to populate a list box or a combo box as the
code works for both...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top