How do I refer to a controls object, on a worksheet, using a variable name?

后端 未结 4 1914
慢半拍i
慢半拍i 2021-01-11 20:06

I have added a ListBox to a SHEET (not to a \"UserForm\") I did this using the mouse. I clicked the little Hammer and Wrench icon.

This ListBox seems to be easily re

4条回答
  •  逝去的感伤
    2021-01-11 20:42

    Change the sub signature to match this:

    Sub populate_listbox(LB As MSForms.ListBox, dataArray As Variant)

    Now you can pass it like you were trying to originally.

    NOTE: This only works if you used the "ActiveX" version of the listbox. I'm assuming you are because you are able to call ListBox1 straight from a module.

    PS: The ActiveX controls are members off of the parent sheet object. So if you have the listbox1 on sheet1, you can also call it like Sheet1.ListBox1 so you don't get confused if you end up with multiple sheets with multiple listboxes. Also, you may want to change the name just to make it easier on yourself.

提交回复
热议问题