excelvba

How to move data from next row to top automatically after clearing?


I want row 35 (32) data move to cell B4 automatically after clearing data from row 1 to 34.

Private Sub ClearContents_Click()
    Range("B4:J34").ClearContents
End Sub

I am still learning VBA. So, I don't know what to put.

I tried Rows.Delete Range("4:34").

It didn't work.


Solution

  • The Rows method returns a Range object, and "4:34" isn't a valid argument to the Delete method of Range.

    Range("4:34").Delete should do what you intend.