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

后端 未结 13 2097
[愿得一人]
[愿得一人] 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:52

    Simple answer: no.

    What I've done in the past is load the headings into row 0 then set the ListIndex to 0 when displaying the form. This then highlights the "headings" in blue, giving the appearance of a header. The form action buttons are ignored if the ListIndex remains at zero, so these values can never be selected.

    Of course, as soon as another list item is selected, the heading loses focus, but by this time their job is done.

    Doing things this way also allows you to have headings that scroll horizontally, which is difficult/impossible to do with separate labels that float above the listbox. The flipside is that the headings do not remain visible if the listbox needs to scroll vertically.

    Basically, it's a compromise that works in the situations I've been in.

提交回复
热议问题