要將B欄到E欄的資料存入陣列,因為只有四欄,所以我用前輩教的方式:
ar = Array("B", "C", "D","E")
For i = 2 To .Cells(.Rows.Count, 1).End(xlUp).Row
ReDim Preserve Ay(s) '將資料存入陣列
Ay(s) = Array(.Cells(i, ar(0)).Value, .Cells(i, ar(1)).Value, .Cells(i, ar(2)).Value, .Cells(i, ar(3)).Value)
s = s + 1
這樣就可以存入陣列了,可是如果有20多欄的資料要存,很顯然這種方式會很累,不知該如何做才好。
還有當資料都移轉完了以後,有一些非連續性儲存格的資料想要把它刪除,如:
With Sheet1
'.[C1].ClearContents
'.[D4].ClearContents
'.[G10].ClearContents
'.[N4:N6].ClearContents
'.[B11:AU12].ClearContents
End With
有沒有辦法用陣列的方式簡化上面的程式碼? |