Excel VBA复制粘贴错误

我有两张相同的数据

ABC 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中的值也被删除。 并没有被用于所有的床单。 只有活动工作表。

A With … End With语句可以在一个命令块中携带一个父工作表引用,但是您必须在每个.Range.Cells引用前添加句点(又.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