其實小弟就是在探討之前oobird大大你幫小弟寫的那2個程式碼
程式碼1>
Private Sub CommandButton1_Click()
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
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
End Sub
這時的k值是什麼
所以小弟用
以下程式碼去試
程式碼2>
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
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
[q9] = k
結果如附件按鍵test3執行結果
在附件中執行結果是18
那是不是在程式碼1中的最後那2行程式碼中的k值就是18?
若是~~~小弟就更不懂了~~~~
Sheets("2").UsedRange = ""
Sheets("2").[a5].Resize(k, 10) = arr
或許小弟對Resize的意義有所誤解~~~~
或根本不懂Sheets("2").[a5].Resize(k, 10) = arr這句程式碼的意思~~~
還煩請解惑~~~作者: Hsieh 時間: 2010-9-10 20:21