我试图清除工作表上除特定范围之外的所有单元格的内容。我试图将范围复制到剪贴板然后再将它粘贴在同一个地方,但是擅长通常是棘手的野兽 - 它不想玩球。
我希望保持不变的范围是AB1:AC5。
任何建议已经融化......
(这是我的代码)
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
答案 0 :(得分:3)
改为使用数组:
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