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
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作者: oobird 時間: 2010-9-6 22:28
If rng(i, 11) - rng(i, 10) <> 0 Then
這一行視你要加或減作者: oak0723-1 時間: 2010-9-7 00:30
陣列1>
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
陣列2>
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
小弟比較了這2個陣列
發現在陣列2的rng變數的定義
rng = .Range(.[c10], .[m83].End(3))
等於設定了rng的起始與終止範圍
而在陣列1的r變數
是受制於變數a而終止
變數a的定義為
a = Sheets("1").[c10].CurrentRegion
這等於沒有設定變數a的終止範圍
所以大大你才將陣列1稱之為變動陣列
陣列2稱之為固定陣列
而非單純以dim或redim作判別基準區分固定或變動陣列?
小弟這樣理解正確嗎?作者: luhpro 時間: 2010-9-7 22:10