如何将数据范围复制到另一个工作表的最后一行?

时间:2020-08-12 15:25:53

标签: excel vba

我试图将另一工作表中的一行复制到数据跟踪表的最后一行。

我收到应用程序定义或对象定义的错误。

services:
    App\EventListener\ChangePasswordListener:
        arguments:
            - '@security.token_storage'
            - '@router'
        tags:
            - { name: kernel.event_listener, event: kernel.request, method: onKernelRequest, priority: -100 }

1 个答案:

答案 0 :(得分:0)

您不需要使用SelectActivate之类的东西。由于可以在VBA中将事物声明为对象,因此可以使用它执行大多数操作,而不必使用任何操作。尝试以下代码:

Sub CopyFromOneSheetToAnother()

    Dim oCopyFromWS As Worksheet: Set oCopyFromWS = ThisWorkbook.Worksheets("Sheet3")           '<- Change the sheet name to the sheet you want to copy from
    Dim oCopyToWS As Worksheet: Set oCopyToWS = ThisWorkbook.Worksheets("Sheet4")               '<- Change the sheet name to the sheet you want to copy to
    Dim iLR As Long: iLR = oCopyToWS.Cells(oCopyToWS.Rows.Count, 1).End(xlUp).Row + 1
    
    oCopyFromWS.Range("A20:AB20").Copy oCopyToWS.Range("A" & iLR)
    
End Sub