Sub yy()
Dim rng, arr, i%, j%, k%
With Sheets("1")
rng = .Range(.[c10], .[m83].End(3))
End With
ReDim arr(1 To UBound(rng), 1 To 10)
For i = 1 To UBound(rng)
If rng(i, 11) - rng(i, 10) <> 0 Then
k = k + 1
問題 >這裡的k的起始值並沒寫...這樣沒有寫的狀況是不是代表k是從0開始
For j = 1 To 6
arr(k, j) = rng(i, j)
Next
arr(k, 8) = rng(i, 8) - rng(i, 6)
arr(k, 9) = arr(k, 8) - arr(k, 6)
arr(k, 10) = rng(i, 11) + rng(i, 10)
End If
Next
Sheets("2").UsedRange = ""
Sheets("2").[a5].Resize(k, 10) = arr
問題 >這裡的k不是已經跳出for-next迴圈..且該回圈也沒有Preserve...那不是k值就沒記憶?k不就是空的嗎?
End Sub作者: GBKEE 時間: 2010-9-8 13:06
那在請教大大
由這個程式碼
Dim a, r%, i%, arr()
a = Sheets("1").[c10].CurrentRegion
r = 1
For i = 1 To UBound(a)
ReDim Preserve arr(1 To 3, 1 To r)
arr(1, r) = a(i, 1): arr(2, r) = a(i, 2): arr(3, r) = a(i, 3)
r = r + 6
Next
[j9] = r
得到r445
那請教
下列這個程式碼for-next後的r(紅字標示)也是445嗎
Dim a, r%, i%, arr()
a = Sheets("1").[c10].CurrentRegion
r = 1
For i = 1 To UBound(a)
ReDim Preserve arr(1 To 3, 1 To r)
arr(1, r) = a(i, 1): arr(2, r) = a(i, 2): arr(3, r) = a(i, 3)
r = r + 6
Next
Sheets("2").[c4].Resize(r - 6, 2) = Application.Transpose(arr)
Sheets("2").[k4].Resize(r - 6, 1) = Application.Transpose(Application.Index(arr, 3))
以上詳附件作者: Hsieh 時間: 2010-9-9 21:00