我正在尝试清除工作表上除特定范围之外的所有单元格的内容。我尝试将范围复制到剪贴板,然后将其再次粘贴到同一位置,但是 excel 是通常棘手的野兽 - 它不想玩球。
我希望保持不变的范围是 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
最佳答案
使用数组代替:
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
关于VBA - 范围 ("All cells but a few"),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38606800/