PC Review


Reply
Thread Tools Rate Thread

Clearing cells in a range upon exitting Excel

 
 
E
Guest
Posts: n/a
 
      14th Jan 2009
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.
 
Reply With Quote
 
 
 
 
ryguy7272
Guest
Posts: n/a
 
      14th Jan 2009
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---

--
RyGuy


"E" wrote:

> 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" <(E-Mail Removed)> wrote in message
> > news:2E7B80E1-183C-428C-BC9A-(E-Mail Removed)...
> > > 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.

> >
> >

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
clearing values of cells in named range(s) so the cells are empty BRC Microsoft Excel Programming 1 10th Jan 2010 06:54 AM
Re: Clearing cells in a range upon exitting Excel Rick Rothstein Microsoft Excel Programming 1 14th Jan 2009 08:16 PM
RE: Clearing cells in a range upon exitting Excel Mike H Microsoft Excel Programming 0 14th Jan 2009 07:25 PM
Re: Clearing cells in a range upon exitting Excel Don Guillett Microsoft Excel Programming 0 14th Jan 2009 07:24 PM
Filter, clearing visible cells in a range, but leaving hidden cells Jason Chapman Microsoft Excel Discussion 2 27th Jun 2008 02:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:03 PM.