简体   繁体   English

使用VBA excel从一张工作表中复制表格并将其粘贴到另一张工作表的下一个空行中

[英]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.

相关问题 复制列直到一张纸的最后一行,然后粘贴到另一张纸的下一个空行 - Copy columns until last row from one sheet and paste to the next empty row of another sheet Excel 2007 VBA:如何从一张纸上的动态范围复制和粘贴到另一张纸的第一行? - Excel 2007 VBA: How do I copy and paste from a dynamic range on one sheet to the first empty row of another sheet? 使用excel VBA将数据从一张纸复制并粘贴到另一张纸,然后从第二张纸复制到第三张纸 - Copy and paste data from one a sheet to another sheet, and from second sheet to third using excel VBA Excel VBA-将范围从一张纸复制到另一张纸,下一个空行 - Excel VBA - Copy range from one sheet to another, next empty row 复制并粘贴到下一个空行中的另一个工作表 - Copy and paste to another sheet in the next empty row 使用宏从一个工作表中复制多个范围,然后将其粘贴到第一行中的另一工作表中 - Using macro to copy multiple ranges from one sheet, and paste them into another sheet in the first empty row 用于将数据从第 2 行复制到一张工作表上的最后一行数据并粘贴到另一张工作表的第一空行的 VBA 代码 - VBA Code to Copy Data from Row 2 to Last Row of Data on One Sheet and Paste to the First Empty Row of Another Sheet VBA从自动筛选器中复制并粘贴到另一张工作表中,输出一行 - VBA Copy and Paste in another Sheet from AutoFilter outputting one row 将行从一张纸复制到另一张纸,然后在7列后使用Excel中的vba转到下一行 - Copy rows from one sheet into other sheet and after 7 columns go to next row using vba in excel 在 Excel 中将行从一个工作表复制并粘贴到另一个工作表 - Copy and paste row from one sheet to another in Excel
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM