操作 11 列的列表框

Manipulate a listbox of 11 columns

我有一个包含 11 列的列表框。当我尝试向其中一列添加数据时,出现错误。

ListBox1.Column(10, j) = shtG.Cells(k, 13)

我不明白为什么会这样,用户窗体上的列表框的 ColumnCount 为 11

错误 我得到:

"Run-time error 380: Unable to set Column property. Invalid property value."

所选单元格的值为"Group 16"。


更多信息:

代码:

'adding this doesn't help
ListBox1.Clear
ListBox1.ColumnCount = 20

    While shtG.Cells(k, 1) <> ""
        If 'some long working condition Then

            frmTP.ListBox1.AddItem (shtG.Cells(k, kolID))
            frmTP.ListBox1.Column(1, j) = shtG.Cells(k, kolVnm) & strSpace & shtG.Cells(k, kolTV) & strSpace & shtG.Cells(k, kolAnm)
            frmTP.ListBox1.Column(2, j) = shtG.Cells(k, 5)
            frmTP.ListBox1.Column(3, j) = shtG.Cells(k, 6)
            frmTP.ListBox1.Column(4, j) = shtG.Cells(k, 7)
            frmTP.ListBox1.Column(5, j) = shtG.Cells(k, 8)
            frmTP.ListBox1.Column(6, j) = shtG.Cells(k, 9)
            frmTP.ListBox1.Column(7, j) = shtG.Cells(k, 10)
            frmTP.ListBox1.Column(8, j) = shtG.Cells(k, 11)
            frmTP.ListBox1.Column(9, j) = shtG.Cells(k, 12)
            frmTP.ListBox1.Column(10, j) = shtG.Cells(k, 13)
            j = j + 1
        End If
        k = k + 1
    Wend

这就是我的意思(您可以通过将 sheet 数据加载到数组中开始并处理它来提高性能,而不是经常调整数组的大小,但它会分散注意力关键点在这里!):

Dim vData()
j = 0
While shtG.Cells(k, 1) <> ""
    If 'some long working condition Then
        ReDim Preserve vData(0 To 10, 0 To j)
        vData(0, j) = shtG.Cells(k, kolID).Value
        vData(1, j) = shtG.Cells(k, kolVnm) & strSpace & shtG.Cells(k, kolTV) & strSpace & shtG.Cells(k, kolAnm)
        vData(2, j) = shtG.Cells(k, 5)
        vData(3, j) = shtG.Cells(k, 6)
        vData(4, j) = shtG.Cells(k, 7)
        vData(5, j) = shtG.Cells(k, 8)
        vData(6, j) = shtG.Cells(k, 9)
        vData(7, j) = shtG.Cells(k, 10)
        vData(8, j) = shtG.Cells(k, 11)
        vData(9, j) = shtG.Cells(k, 12)
        vData(10, j) = shtG.Cells(k, 13)
        j = j + 1
    End If
Wend
frmTP.ListBox1.Column = vData