我试图在一个名为“部门”(A1:A10,C1:C10,E1:E10)的表中显示一个不连续的单元格范围到一个多列列表框。
我在这里找到了一个示例,但它只显示表格的第一行(A1,C1,E1)。
谁能帮我编辑这段代码并解释它是如何工作的?:)
提前谢谢你。
Option Explicit
Private Sub CommandButton1_Click()
Dim Ar() As String
Dim rng As Range, cl As Range
Dim i As Long
Set rng = Range("A1,C1,E1")
i = 1
For Each cl In rng
ReDim Preserve Ar(1, 1 To i)
Ar(1, i) = cl.Value
i = i + 1
Next
With ListBox1
.ColumnCount = i - 1
.ColumnWidths = "50;50;50"
.List = Ar
End With
End Sub