Share via

VBA Paste into next empty row

Anonymous
2016-11-18T06:10:11+00:00

Sub Btn_Add()

    Selection.Copy

    If Range("E13") = "" Then

        Range("E13").PasteSpecial xlPasteValues

    Else

        Range("E13").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValues

    End If

End Sub

This VBA copies the selected cell then pastes it into column E in the next available, empty cell.

I have this code, and its returning an application define/object defined error on the else statement.

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

1 answer

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2016-11-18T08:13:18+00:00

            Range("E13").End(xlDown).Offset(1, 0).PasteSpecial xlPasteValues

    I have this code, and its returning an application define/object defined error on the else statement.

    If .End(xlDown) goes to the bottom of the sheet then .Offset(1, 0) is the next row below... => error.

    Search always from the bottom of the sheet upwards.

    Andreas.

    Sub Btn_Add()

      Selection.Copy

      With Range("E13")

        If IsEmpty(.Value) Then

          .PasteSpecial xlPasteValues

        Else

          .Offset(Rows.Count - .Row).End(xlUp).Offset(1).PasteSpecial xlPasteValues

        End If

      End With

    End Sub

    Was this answer helpful?

    2 people found this answer helpful.
    0 comments No comments