我总是使用Resize()函数:
Cells(1, "B").Resize(counter, ColumnCount).value = MyArraY
但MyArray总是在内部使用不同格式的数组来将项目放入工作表
有时我需要使用相同的范围
so if MyArraY filling this way
For y = 1 To .ListCount
If .Selected(y - 1) Then
' load subarray into array
ListB = vbNullString
For f = 1 To .ColumnCount
ListB = ListB & "·" & .List(y - 1, f - 1)
Next f
MyArraY(counter) = Split(Mid(ListB, 2), "·")
counter = counter + 1
End If
Next y
I must use
Cells(1, "B").Resize(counter, ColumnCount).value = Application.index(MyArraY, 0, 0)
有时
if MyArraY filling this way
counter = 10
ReDim MyArraY(1 To counter)
For yy = 1 To counter
z = z + 1
If Cells(yy, 6).value = vbNullString Then
MyArraY(z) = Cells(yy, 5).value
Else
MyArraY(z) = Cells(yy, 6).value
End If
Next yy
then
Cells(1, "B").Resize(counter, ColumnCount).value = Application.Transpose(MyArraY)
somtimes
if
MyArraY= range(Cells(1, 1).Address, Cells(10, 5).Address).value
Cells(1, "B").Resize(counter, ColumnCount).value = MyArraY
我如何知道MyArray何时使用此类型?因为我总是必须选择合适的类型,因为我不知道数据在数组中的位置
答案 0 :(得分:-1)
您需要掌握阵列的尺寸。我不认为你做了ReDim Preserve来获得阵列的确切尺寸。这将有助于您正确调整大小。 请参阅:http://msdn.microsoft.com/en-us/library/w8k3cys2.aspx