VBA 代码复制并粘贴到另一张表的最后一行

VBA 代码复制并粘贴到另一张表的最后一行
Sub CopyRowsWithNUMBER()

Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet


Set Source = ActiveWorkbook.Worksheets("Completed Items")
Set Target = ActiveWorkbook.Worksheets("Week 24")

j = 15
For Each c In Source.Range("D1:D200")
    If c = "24" Then
       Source.Rows(c.Row).Copy Target.Rows(j)
       j = j + 1
    End If
    
   
Next c
End Sub

这是我的代码,我需要知道如何设置它以将我的代码粘贴到目标表中的第一个可用行。现在设置为将其移动到第 15 行,我这样做是作为一种临时解决方法,因为这实际上是我的目标数据表的当前最后一行,但这当然会改变。

答案1

调整以下几行以找到第一个可用行:

    Dim lastRow As Long
    'Finds the last occupied cell on Column A. Change 1 to another number. B=2, D=4, E=5, etc
    lastRow = Cells(Rows.Count, 1).End(xlUp).Row

    'Set value to +1 to get the next available row
    lastRow = lastRow + 1

相关内容