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

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

    Another variant on Lunatik's response is to use a local boolean and the change event so that the row can be highlighted upon initializing, but deselected and blocked after a selection change is made by the user:

    Private Sub lbx_Change()
    
        If Not bHighlight Then
    
            If Me.lbx.Selected(0) Then Me.lbx.Selected(0) = False
    
        End If
    
        bHighlight = False
    
    End Sub
    

    When the listbox is initialized you then set bHighlight and lbx.Selected(0) = True, which will allow the header-row to initialize selected; afterwards, the first change will deselect and prevent the row from being selected again...

提交回复
热议问题