How to populate data from a range (multiple rows and columns) to listbox with VBA

前端 未结 3 1111
长情又很酷
长情又很酷 2021-01-14 09:23

I am having trouble with how to put the data from the range with multiple columns and rows to a listbox.

Assume I have a range rng which multiple columns and rows I

3条回答
  •  一个人的身影
    2021-01-14 09:58

    I am assuming you want to populate 3 columns

    Dim currRange As Range
    Dim i As Integer
    With Selection
    For Each currRange In Range("yourRange")
            i = i + 1
            If i = 1 Then .AddItem cell.Value
            If i = 2 Then .List(.ListCount - 1, 1) = "1"
            If i = 3 Then
                .List(.ListCount - 1, 2) = cell.Offset(0, 2).Value
                i = 0
            End If
    Next
    End With
    

    I am assuming you have 3 columns.

提交回复
热议问题