ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Clearing cells in a range upon exitting Excel (https://www.excelbanter.com/excel-programming/422469-re-clearing-cells-range-upon-exitting-excel.html)

Mike H

Clearing cells in a range upon exitting Excel
 
Hi,

Before_Close is a workbook event. In VB editor double click 'ThisWorkbook'
and paste the code in there. Note that here you must qualify the range with a
sheet name.

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Sheet1").Range("b18:l40").ClearContents
End Sub

Mike

"E" wrote:

Like the title says, I am working on a project in Excel that requires that
the data entered in a range be cleared. I tried the following code in the
deactivate event of the worksheet:

Private Sub Worksheet_Deactivate()
Range("b18:l40").ClearContents
End Sub

This works fine if I switching worksheets but I would like the clear to
occur when closing Excel. I did not see a "OnClose" type event where I could
put the code for clearing the selection.

Thanks in advance.



All times are GMT +1. The time now is 02:57 PM.

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