操纵11列的列表框

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

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

我不明白为什么会发生这种情况,用户窗体上的列表框的列数为11

我得到的错误

“运行时错误380:无法设置列属性。无效的属性值。

所选单元格的值是“组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 

这就是我的意思(你可以通过将表单数据加载到一个数组中来开始和处理数据,而不是经常调整数组大小,但是这会分散注意力)。

 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