![]() |
Unable to pass a control to a sub
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? |
Unable to pass a control to a sub
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... -- HTH... Jim Thomlinson "Paolo Sardi" wrote: 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? |
All times are GMT +1. The time now is 06:00 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com