How to add headers to a multicolumn listbox in an Excel userform using VBA

后端 未结 13 2098
[愿得一人]
[愿得一人] 2020-11-30 09:01

Is it possible to set up the headers in a multicolumn listbox without using a worksheet range as the source?

The following uses an array of variants which is assigne

13条回答
  •  无人及你
    2020-11-30 09:44

    I like to use the following approach for headers on a ComboBox where the CboBx is not loaded from a worksheet (data from sql for example). The reason I specify not from a worksheet is that I think the only way to get RowSource to work is if you load from a worksheet.

    This works for me:

    1. Create your ComboBox and create a ListBox with an identical layout but just one row.
    2. Place the ListBox directly on top of the ComboBox.
    3. In your VBA, load ListBox row1 with the desired headers.
    4. In your VBA for the action yourListBoxName_Click, enter the following code:

      yourComboBoxName.Activate`
      yourComboBoxName.DropDown`
      
    5. When you click on the listbox, the combobox will drop down and function normally while the headings (in the listbox) remain above the list.

提交回复
热议问题