0

I want to clear the contents out of cells A2:C.

I have column names in A1, B1, and C1 that I don't want cleared.

Sub Clear_Contents()
Range("A2:C").ClearContents
End Sub

I get an error.

I can change the range to be "A2:C100" or any other hard coded number but I want to clear from A2:A, B2:B, and C2:C.

Community
  • 1
  • 1
Conner
  • 271
  • 6
  • 21
  • 5
    You can either find the last row with values: https://stackoverflow.com/questions/11169445/find-last-used-cell-in-excel-vba or just set it to the last row on the sheet: `Range("A2:C" & Rows.Count).ClearContents` – Scott Craner Aug 24 '22 at 19:12
  • `A2:C` is not a valid range reference in Excel. – BigBen Aug 24 '22 at 19:32
  • 1
    Optionally, without concatenation: `Range("A2", Cells(Rows.Count, "C")).ClearContents` – VBasic2008 Aug 24 '22 at 19:41

1 Answers1

1

Here's another way

Range("A2").Resize(Rows.Count-1,3).ClearContents
Dick Kusleika
  • 32,673
  • 4
  • 52
  • 73