excelvbarowcountpasting

Identifying Total Number of Rows, then Copying and Pasting a values to the number of rows


I'm looking to create a macro that will essentially identify the total number of rows on a sheet. Then take the values in a range on another sheet, copy that range, and paste it until it reaches the total number of rows that was identified on the first sheet. I am NOT looking to take a set of values and copy it to the last row of another sheet.

This is what I have so far. I'm having trouble trying to find the next step to take to accomplish my goal. I think I'm close, but my knowledge of variables is very limited.

Public Sub Delegation()

    Dim lastrow As String
    lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
    Worksheets("delegating").Range("A1:A13").Copy _

End Sub

Solution

  • You can try something like this:

    Public Sub Delegation()
    
        Dim lastrow As Long
        lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row + 1
    
        With Worksheets("delegating")
            .Range("A1:A13").AutoFill Destination:=.Range("A1:A" & lastrow), _
                                      Type:=xlFillCopy
        End With 
    End Sub