VBA – 范围(“所有单元,但less数”)

我正在尝试清除工作表中除特定范围之外的所有单元格的内容。 我试图将范围复制到剪贴板上,然后再次粘贴到同一个地方,然而excel是通常棘手的野兽 – 它不想玩球。

我想保持相同的范围是AB1:AC5。

任何build议Apprichiated …

(这是我的代码)

Sub Button21_Click() Application.ScreenUpdating = False With Worksheets(2) .Range("AB1:AC5").Copy .Cells.ClearContents .Paste(Destination:=Sheets("Data").Range("AB1")) End With Application.ScreenUpdating = True End Sub 

使用数组来代替:

 Sub Button21_Click() Application.ScreenUpdating = False Dim oldValues As Variant With Worksheets(2) oldValues = .Range("AB1:AC5").Value .Cells.ClearContents .Range("AB1:AC5").Value = oldValues End With Application.ScreenUpdating = True End Sub