標題:
型態不符
[打印本頁]
作者:
y663258
時間:
2011-2-11 08:57
標題:
型態不符
各位大大,程式碼執行發生型態不符,要如何修正請協助謝謝。
作者:
GBKEE
時間:
2011-2-13 15:06
回復
1#
y663258
刪掉 Sheet2.[B5].Resize(x , 31) = Application.Transpose(Application.Transpose(Ay))
改成如下:
For i = 0 To UBound(Ay)
Sheet2.[B5].Offset(i).Resize(, 31) = Ay(i)
Next
作者:
y663258
時間:
2011-2-14 09:06
GBKEE 版主,謝謝您幫忙這麼改一下就能順利操作,能否解釋二者差別,謝謝。
作者:
GBKEE
時間:
2011-2-16 16:14
回復
3#
y663258
Dim A As Range,
ar
(31) , Ay()
ar 宣告的是一維陣列 Ay 是動態陣列
ReDim Preserve Ay(x)
ReDim Preserve Ay(x) 也是一維陣列
Ay(x) = ar
下列程式碼為二維陣列的用法
Sub Ex()
Dim Ar(), x As Integer, i As Integer
For x = 0 To 10
ReDim Preserve Ar(1 To 10, x) '重新宣告為二維陣列
For i = 1 To UBound(Ar, 1)
Ar(i, x) = x & "- " & Chr(64 + i) & " " & i
Next
Next
[a1].Resize(UBound(Ar, 1), UBound(Ar, 2) + 1) = Ar
[a1].End(xlDown).Offset(2).Resize(UBound(Ar, 2) + 1, UBound(Ar, 1)) = Application.Transpose(Ar)
End Sub
複製代碼
歡迎光臨 麻辣家族討論版版 (http://forum.twbts.com/)