Clearing cells in a range upon exitting Excel

  • Thread starter Thread starter E
  • Start date Start date
E

E

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.
 
Should be like this:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Call...your macro name
End Sub

I use this all the time. Something very simple; effective too!
Place the code in 'ThisWorkbook'.

Regards,
Ryan---
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top