我有两张相同的数据
A B C
5 6
4 3 3 公式1
Sub Button1_Click()
Dim Current As Worksheet
Range("A2").Copy _
Destination:=Range("A1")
Range("A2").ClearContents
End Sub这个公式对我有用。但我需要把这个脚本应用到所有的床单上,
公式2
Dim Current As Worksheet
' Loop through all of the worksheets in the active workbook.
For Each Current In ThisWorkbook.Worksheets
With Current
Range("A2").Copy _ Destination:=Range("A1")
Range("A2").ClearContents
End With
Next Current
End Sub->它可以工作,但是A1中的值也被删除了。而且它并不适用于所有的床单。只有活动床单。
发布于 2016-02-12 05:24:46
和..。以语句结尾可以在命令块中携带父工作表引用,但必须在每个.Range或.Cells引用前缀加上句点(也称为句号),才能接受父工作表关系。
Dim Current As Worksheet
' Loop through all of the worksheets in the active workbook.
For Each Current In ThisWorkbook.Worksheets
With Current
.Range("A2").Copy Destination:=.Range("A1")
.Range("A2").ClearContents
End With
Next Current注意.Range而不是Range。
https://stackoverflow.com/questions/35355319
复制相似问题