【发布时间】:2021-08-30 14:44:34
【问题描述】:
我在UserForm1 中有一个ListBox1。当我将多行数组发送到.List 时,一切正常。但是当我只发送一个单行数组时,ListBox1 中的值在第一列中排列在另一个下方。独立使用Application.Transpose。
我尝试编写一个条件和一个 for 循环,但它不起作用。
运行时错误 381
无法设置 List 属性。无效的属性数组索引。
.AddItem 超过 10 列,无法使用
您还有其他解决方案吗?
Dim sumItem As Integer: sumItem = 0 'later between 1 and 5000
.
.
ReDim Preserve arrSort(0 To (columnCount - 1 + 2), 0 To sumItem - 1)
.
.
Call Load(UserForm1) 'to be able to manipulate components
If sumItem = 1 Then 'if only one ROW is loaded in the array
Dim qq As Byte
For qq = 0 To (columnCount - 1)
UserForm1.ListBox1.List(0, qq) = arrSort(qq, 0) 'need to fill the LISTBOX ROW here
Next qq
ElseIf sumItem > 1 Then
UserForm1.ListBox1.List = Application.Transpose(arrSort) 'if more than one ROW is filled, this works
Else
End If
UserForm1.Show
感谢@Tim Williams 这对我有用:
Dim sumItem As Integer: sumItem = 0 'later between 1 and 5000
.
.
ReDim Preserve arrSort(0 To (columnCount - 1 + 2), 0 To sumItem - 1) 'the dimensions are reversed
.
.
Call Load(UserForm1) 'to be able to manipulate components
If sumItem = 1 Then 'if only one ROW is loaded in the array
Dim qq As Byte
Dim arrTmp(0 To 0, 0 To (columnCount - 1)) As Variant 'auxiliary array for dimension exchange
For qq = 0 To (columnCount - 1)
arrTmp(0, qq) = arrSort(qq, 0)
Next qq
UserForm1.ListBox1.List = arrSort
ElseIf sumItem > 1 Then
UserForm1.ListBox1.List = Application.Transpose(arrSort) 'if more than one ROW is filled, this works
Else
End If
UserForm1.Show
【问题讨论】: