将数据追加到另一个工作表的最后一行

Append Data to the Last Row of another Worksheet

我只需要从一个 sheet 中抓取一个列(范围),然后附加到另一个 sheet。出于某种原因,我在尝试 运行 粘贴值函数时不断收到错误 1004 - object/application 定义的错误。

如有任何帮助,我们将不胜感激。

    Sub copycontactsiratotpsd()

    Dim LastRowIRA2 As Long
    Dim LastRowIRA As Long
    Dim LastRowPOV As Long
    Dim lastrow As Long




    'activate source sheet
    ActiveWorkbook.Worksheets("IRA").Activate

    'copy from rev to ira AG to match # of rows for TPRM Contacts before appending
    ActiveWorkbook.Sheets("Rev").Range("B2:B15000").SpecialCells(xlCellTypeVisible).Copy
    ActiveWorkbook.Sheets("IRA").Range("AG2:AG15000").PasteSpecial xlPasteValues

    'define last rows for all three instances
    LastRowIRA = ActiveSheet.Range("A1").CurrentRegion.Rows.count
    LastRowIRA2 = ActiveSheet.Range("AG1").CurrentRegion.Rows.count
    lastrow = WorksheetFunction.Max(Sheets("TPD").Cells(Rows.count, "A").End(xlUp).Row)

    LastRowPOV = ActiveWorkbook.Sheets("TPD").Range("A1").CurrentRegion.Rows.count

    'if the number of lastrow in source sheet is equal to total VISIBLE last row within reference sheet then
        If LastRowIRA = LastRowIRA2 Then

            ActiveWorkbook.Worksheets("IRA").Activate

            'copy the data needed, values are generally less than 10000 rows
            ActiveWorkbook.ActiveSheet.Range("B2:B10000").Copy

            ActiveWorkbook.Sheets("TPD").Range("A", lastrow).PasteSpecial xlPasteValues

'LINE WITH ERROR ABOVE




        'else display msg for error handling
        Else: MsgBox "Row Count is off! *CHECK*"

        End If


    ActiveWorkbook.Worksheets("IRA").Activate
    Columns(33).EntireColumn.Delete

    End Sub

允许回答结束:

ActiveWorkbook.ActiveSheet.Range("B2:B10000").Copy
ActiveWorkbook.Sheets("TPD").Cells(lastrow, "A").PasteSpecial xlPasteValues

或者:

ActiveWorkbook.ActiveSheet.Range("B2:B10000").Copy
ActiveWorkbook.Sheets("TPD").Range("A" & lastrow).PasteSpecial xlPasteValues