[英]copy a table from one Sheet and paste it in the next empty row of another Sheet using VBA excel
I want to copy and paste a table from one Sheet to another Sheet in the next empty row. 我想将表格从一个工作表复制并粘贴到下一个空行中的另一个工作表。 The problem is that my code doesn't search the next empty row. 问题是我的代码不会搜索下一个空行。 it gives me always the first row as the empty one. 它总是给我第一行作为空行。
this is my Code: 这是我的代码:
Sub AddToPriceSummary()
Dim lastrow As Long
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Set copySheet = Worksheets("Sheet2")
Set pasteSheet = Worksheets("Sheet3")
lastrow = Range("A100000").End(xlUp).Row
copySheet.Range("A2:AS10").Copy
pasteSheet.Cells(lastrow + 1, 1).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Application.ScreenUpdating = True
End Sub
So here lastrow
is always 1 所以在这里lastrow
总是1
Any help? 有什么帮助吗?
Your lastrow
is not qualified with pasteSheet
. 您的lastrow
不符合pasteSheet
。
Try: 尝试:
lastrow = pasteSheet.Range("A100000").End(xlUp).Row
A safer way to find the lastrow
using the Find
function : 使用Find
函数Find
lastrow
更安全方法:
lastrow = pasteSheet.Cells.Find(What:="*", After:=pasteSheet.Cells(1), Lookat:=xlPart, LookIn:=xlFormulas, SearchOrder:=xlByRows, SearchDirection:=xlPrevious, MatchCase:=False).Row
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.