How to get selected value in multicolumn listbox

后端 未结 4 1700
长发绾君心
长发绾君心 2020-12-06 21:25

I have a multicolumn listbox in my userform and I would like to get all the values of the elements which are in the selected row in the listbox.

Here is my userform:

4条回答
  •  遥遥无期
    2020-12-06 22:10

    It's a 6column list box and the 3rd column would be the multiplier hence the "(x)". You may also rearrange the list to how you like it.

    Private Function selList() As String
    Dim i As Long
    
    For i =LBound(lstListBox1.List) To UBound(lstListBox1.List)
        If lstListBox1.Selected(i) Then
            selList = selList & lstListBox1.List(i) & " " & lstListBox1.List(i, 1) _
            & "(x" & lstListBox1.List(i, 3) & ")" & " " & lstListBox1.List(i, 2) & " " & lstListBox1.List(i, 4) & ", "
        End If
    Next i
    
    If selList= "" Then
        selList= ""
    Else
        selList= Left(selList, Len(selList) - 2)
    End If
    
    MsgBox selList
    End Function
    

提交回复
热议问题