我写了一个按钮来复制一个范围内的输入,然后逐行粘贴到其他地方的表格中(即在一个名为' end'的单元格上方有一条线的表格中)。但是当它运行时,它也会将输入粘贴在不同标签上的相同单元格中!知道我做错了吗?
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
Dim Sheet As Worksheet
For Each Sheet In ThisWorkbook.Worksheets
If Sheet.Name <> "Definitions" And Sheet.Name <> "fx" And Sheet.Name <> "Needs" Then
Sheets("sheet1").Range("A9:G9 ").Copy
Sheet.Cells(Range("end").End(xlUp).Row + 1, 1).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End If
Next
Application.ScreenUpdating = True
End Sub
答案 0 :(得分:2)
如果你想将它从sheet1复制到sheet1上的另一个地方,这将更简单:
Private Sub CommandButton2_Click()
Application.ScreenUpdating = False
With Worksheets("sheet1")
'this will be even faster than the copy method below
.Cells(.Range("end").End(xlUp).Row + 1,1).Resize(1,7).Value = _
.Range("A9:G9").Value
'this is the copy method that is slower
'.Range("A9:G9").Copy
'.Cells(.Range("end").End(xlUp).Row + 1,1).PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:=False, Transpose:=False
End With
End Sub