Fill in the Next Empty Row in the Worksheet


October 24, 2001 - by

P.K. asks:

I have a worksheet where I input some values. Upon clicking a macro button, I want the values or its calculated results to be appended to a different sheet or file.

Good question. Let's say the values are in cells C10 and E12 of Sheet1 and you want them appended to the next row in Sheet2.

The real trick here is the code to find the next row on Sheet2. Starting at the last row in Sheet2 (A65536) and then using .End(xlup) will find the last row with data in column A. Adding 1 to that row will point you to the next row for data on Sheet2. Use this code:

Sub CopyThem()
    NextRow = Worksheets("Sheet2").Range("A65536").End(xlUp).Row + 1
    Worksheets("Sheet2").Cells(NextRow, 1).Resize(1, 2).Value = Array( _
        Worksheets("Sheet1").Range("C10").value, _
        Worksheets("Sheet1").Range("E12").value)
End Sub