0

我试图在一个名为“部门”(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
4

1 回答 1

0

也许

Private Sub CommandButton1_Click()
   Dim rng As Range

   Set rng = Range("A1:E10")

   With ListBox1
      .ColumnCount = 3
      .ColumnWidths = "50;50;50"
      ' load 1st, 3rd and 5th columns of range into listbox
      .List = Application.Index(rng, Evaluate("ROW(1:" & rng.Rows.Count & ")"), Array(1, 3, 5))
   End With
End Sub
于 2013-06-12T09:39:27.970 回答