![](/img/trans.png)
[英]Copy columns until last row from one sheet and paste to the next empty row of another sheet
[英]copy a table from one Sheet and paste it in the next empty row of another Sheet using VBA excel
我想將表格從一個工作表復制並粘貼到下一個空行中的另一個工作表。 問題是我的代碼不會搜索下一個空行。 它總是給我第一行作為空行。
這是我的代碼:
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
所以在這里lastrow
總是1
有什么幫助嗎?
您的lastrow
不符合pasteSheet
。
嘗試:
lastrow = pasteSheet.Range("A100000").End(xlUp).Row
使用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.