VBA替代每个

我目前正在使用很多For ... Each在我的代码中的For ... Each循环都会减慢很多,有没有更快的方法?

我听说我可以将范围复制到一个数组,并编辑数组并粘贴回来,但即时编辑数组中的每个单元格有一些问题。

这里是我正在使用的每个代码的当前 – 谢谢。

 Dim cell As Range For Each cell In Sheets("sheet1").UsedRange cell.Value = cell.Value Next cell 

沿着这些线路的东西:

 Dim aCells As Variant Dim x As Long Dim y As Long aCells = Sheets("Sheet1").UsedRange ' Now do something with the array; ' We'll debug.print the contents of each element ' to verify that it matches the cells in the sheet For x = 1 To UBound(aCells, 1) For y = 1 To UBound(aCells, 2) Debug.Print aCells(x, y) Next Next 

试试这个 – 更快,更高效:

 Sheets("sheet1").UsedRange.Value = Sheets("sheet1").UsedRange.Value