gpt4 book ai didi

vba - 操作 11 列的列表框

转载 作者:行者123 更新时间:2023-12-02 19:38:09 25 4
gpt4 key购买 nike

我有一个包含 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

最佳答案

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

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

关于vba - 操作 11 列的列表框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34089309/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com