[英]Copy last row of a sheet and paste in last row of a different sheet VBA
Right now I have a Workbook containing a master sheet and multiple individual customer sheets. 现在,我有一本工作簿,其中包含一个母版纸和多个个人客户纸。 I am writing some code to look at the customer column, copy the row and then paste it in their respective sheet.
我正在编写一些代码来查看“客户”列,复制该行,然后将其粘贴到各自的工作表中。 At the end I want the last row from my template sheet to be pasted as the last row for the customer sheet.
最后,我希望将模板工作表的最后一行粘贴为客户工作表的最后一行。 This is to calculate averages.
这是为了计算平均值。 So far it works but the last row gets pasted to the top of the sheet but not the bottom.
到目前为止,它仍然有效,但是最后一行粘贴到了工作表的顶部,但没有粘贴到底部。 I cant figure out how to get it to be the last row.
我不知道如何使它成为最后一行。
Sub copyPasteDataCustomer()
Dim sws As Worksheet
Dim tws As Worksheet
Dim cel As Range
Set sws = Sheets("Master")
For Each cel In sws.Range("B5:B" & Range("B" & Rows.Count).End(xlUp).Row)
Set tws = Sheets(CStr(cel.Value))
cel.EntireRow.Copy tws.Range("A" & Rows.Count).End(xlUp).Offset(1)
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Canvus")
Dim ws2 As Worksheet: Set ws2 = tws
For i = 2 To ws1.Range("G" & Rows.Count).End(xlUp).Row
ws1.Rows(i).Copy ws2.Rows(ws2.Cells(ws2.Rows.Count, "G").End(xlUp))
Next i
Next cel
End Sub
I ended up deleting the rest of the canvas template to just have the bottom row on the sheet. 我最终删除了画布模板的其余部分,使其仅位于工作表的底部。 Works awesome now.
现在很棒。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.