在下一个空行中复制并粘贴一个设置的范围 [英] Copy and Paste a set range in the next empty row
问题描述
这应该很简单,但我有一个艰难的时刻..我想复制单元格A3到E3,并将它们粘贴到另一个工作表上的下一个空行。我以前使用过这个代码,但是我不得不调整它,而且这次不行。当我运行下面的代码时,我得到一个应用程序定义或对象定义的错误。所有的帮助是赞赏。
This should be simple but I am having a tough time.. I want to copy the cells A3 through E3, and paste them into the next empty row on a different worksheet. I have used this code before in longer strings of code.. but i had to tweak it and it is not working this time. I get a "application-defined or object-defined error" when i run the code seen below. All help is appreciated.
Private Sub CommandButton1_Click()
Dim lastrow As Long
lastrow = Range("A65536").End(xlUp).row
Range("A3:E3").Copy Destination:=Sheets("Summary Info").Range("A:A" & lastrow)
End Sub
推荐答案
请注意Range(...)没有首先限定工作表,因为它将使用当前的Active工作表来制作副本。最好完全符合两张单。请给出一个镜头(请使用复印工作表更改Sheet1):
Be careful with the "Range(...)" without first qualifying a Worksheet because it will use the currently Active worksheet to make the copy from. It's best to fully qualify both sheets. Please give this a shot (please change "Sheet1" with the copy worksheet):
编辑:仅根据以下注释编辑粘贴值。
edited for pasting values only based on comments below.
Private Sub CommandButton1_Click()
Application.ScreenUpdating = False
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Set copySheet = Worksheets("Sheet1")
Set pasteSheet = Worksheets("Sheet2")
copySheet.Range("A3:E3").Copy
pasteSheet.Cells(Rows.Count, 1).End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
这篇关于在下一个空行中复制并粘贴一个设置的范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!