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/422470-re-clearing-cells-range-upon-exitting-excel.html)

Rick Rothstein

Clearing cells in a range upon exitting Excel
 
Use the ThisWorkbook code window instead of the Worksheet's code window
(either pick it from the Project Window or, from any worksheet, right click
the icon immediately to the left of the File menu item and click View Code
from the popup menu that appears). Select Workbook from the left hand drop
down and then select the BeforeClose event from the right hand drop down and
put your code there.

--
Rick (MVP - Excel)


"E" wrote in message
...
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.



e

Clearing cells in a range upon exitting Excel
 
Thanks that worked great. A little different than Access.

E

"Rick Rothstein" wrote:

Use the ThisWorkbook code window instead of the Worksheet's code window
(either pick it from the Project Window or, from any worksheet, right click
the icon immediately to the left of the File menu item and click View Code
from the popup menu that appears). Select Workbook from the left hand drop
down and then select the BeforeClose event from the right hand drop down and
put your code there.

--
Rick (MVP - Excel)


"E" wrote in message
...
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:06 AM.

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