简体   繁体   English

复制工作表的最后一行并粘贴到另一工作表的VBA的最后一行

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

相关问题 VBA复制/粘贴值从上次使用的行的工作表1到工作表2? - VBA copy/paste value from sheet 1 to sheet 2 on last used row? VBA:识别工作表中的最后一行公式(或数据),复制该行,然后在其正下方粘贴一行 - VBA: Identify Last row of formulas (or data) in sheet, copy that row, and then paste one row right below it 用于将数据从第 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 将范围复制到最后一行并粘贴到新工作表上,单元格 A19 之后的第一个空行 - VBA copy range to last row & paste on new sheet, first empty row after cell A19 从第二行复制一列数据,直到其中有数据的最后一行,然后粘贴为另一张表 VBA 上一列的最后一行 - Copy a column of data from the second row until the last row with data in it and paste as the last row in a column on another sheet VBA Excel VBA 过滤器复制并粘贴到单独工作表上最后使用的行下 - Excel VBA Filter Copy and Paste under Last used row on seperate sheet 从记事本复制并粘贴到 Excel 工作表的最后一行 - Copy and paste to the last row of Excel sheet from Notepad 如何将单元格复制到最后一行并粘贴到另一张表格? - How to copy cells to last row and paste to another sheet? VBA将值粘贴到最后一行下方的新表中 - VBA Paste Value into new sheet below last row 多列的数组并粘贴到不同的工作表中,在最后一行获取#ref? - Array for multiple columns and paste into different sheet, getting #ref at the last row?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM