Hello,
For some reason the VBA i'm using to clear all contents below row 1 is now just closing the entire workbook when I press the form control button I have assigned to it. Is there a different code I could use to perform the same task?
Sub ClearData()
With Sheets("Paste Data Here!")
.Rows(2 & ":" & .Rows.Count).ClearContents
End With
End Sub
Thank you,
Joshua
VBA to clear all content below row 1
-
- Administrator
- Posts: 78631
- Joined: 16 Jan 2010, 00:14
- Status: Microsoft MVP
- Location: Wageningen, The Netherlands
Re: VBA to clear all content below row 1
The code looks OK, and it works as intended, without error, when I test it.
Does the problem persist after quitting and restarting Excel?
A slightly different way of writing it:
or
Does the problem persist after quitting and restarting Excel?
A slightly different way of writing it:
Code: Select all
Sub ClearData()
With Sheets("Paste Data Here!")
.Range("A2:A" & .Rows.Count).EntireRow.ClearContents
End With
End Sub
Code: Select all
Sub ClearData()
With Sheets("Paste Data Here!").Cells
.Resize(.Rows.Count - 1).Offset(1).ClearContents
End With
End Sub
Best wishes,
Hans
Hans
-
- StarLounger
- Posts: 94
- Joined: 16 Oct 2021, 16:22
Re: VBA to clear all content below row 1
It was very odd, yeah it would shut down my whole workbook when I used. I've tried your code and it seems to be working properly now.
Thanks again Hans
Thanks again Hans
-
- 4StarLounger
- Posts: 588
- Joined: 14 Nov 2012, 16:06
Re: VBA to clear all content below row 1
Code: Select all
Sub M_snb()
Sheets("Paste Data Here!").usedrange.offset(1).clearcontents
End Sub