ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Erase Data on Sheet (https://www.excelbanter.com/excel-programming/321630-erase-data-sheet.html)

Bill

Erase Data on Sheet
 
How can I erase all the cells after row 1 on a worksheet when the sheet opens.

K Dales[_2_]

Erase Data on Sheet
 
Private Sub Workbook_Open()
Dim ToErase As Range, EraseRows As Integer

Set ToErase = Sheets("SheetName").UsedRange
EraseRows = ToErase.Rows.Count - 1
If EraseRows 0 Then
Set ToErase = ToErase.Offset(1, 0).Range("1:" & EraseRows)
ToErase.ClearContents
End If

End Sub

"Bill" wrote:

How can I erase all the cells after row 1 on a worksheet when the sheet opens.


Gord Dibben

Erase Data on Sheet
 
Bill

You sure you want to do this?

Private Sub Worksheet_Activate()
Range("A2:IV65536").ClearContents
End Sub


Gord Dibben Excel MVP

On Tue, 25 Jan 2005 14:25:03 -0800, "Bill"
wrote:

How can I erase all the cells after row 1 on a worksheet when the sheet opens.




All times are GMT +1. The time now is 08:36 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com