PC Review


Reply
Thread Tools Rate Thread

change cell on exit vba

 
 
Joost
Guest
Posts: n/a
 
      12th Jun 2007
Hello,

Is it possible to clear cells when a workbook is closed with vba
automatically.
I can't figur it out who can help me

Thanks


 
Reply With Quote
 
 
 
 
=?Utf-8?B?QmFyYiBSZWluaGFyZHQ=?=
Guest
Posts: n/a
 
      12th Jun 2007
You'd need to put your code to clear in a Workbook_BeforeClose event.

HTH,
Barb Reinhardt
"Joost" wrote:

> Hello,
>
> Is it possible to clear cells when a workbook is closed with vba
> automatically.
> I can't figur it out who can help me
>
> Thanks
>
>
>

 
Reply With Quote
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      12th Jun 2007
Try this in the before_close workbook event:-

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Set myRange = Worksheets("Sheet1").Range("A1:B100") '< Alter to suit
With myRange
.Select
.Clear
End With
ActiveWorkbook.Save
End Sub

"Joost" wrote:

> Hello,
>
> Is it possible to clear cells when a workbook is closed with vba
> automatically.
> I can't figur it out who can help me
>
> Thanks
>
>
>

 
Reply With Quote
 
Vasant Nanavati
Guest
Posts: n/a
 
      12th Jun 2007
A little shorter:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Range("A1:B100").ClearContents 'alter range to suit
End Sub

_____________________________________________________________________


"Mike H" <(E-Mail Removed)> wrote in message
news:0E5277AD-042F-4F4C-8392-(E-Mail Removed)...
> Try this in the before_close workbook event:-
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Set myRange = Worksheets("Sheet1").Range("A1:B100") '< Alter to suit
> With myRange
> .Select
> .Clear
> End With
> ActiveWorkbook.Save
> End Sub
>
> "Joost" wrote:
>
>> Hello,
>>
>> Is it possible to clear cells when a workbook is closed with vba
>> automatically.
>> I can't figur it out who can help me
>>
>> Thanks
>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      12th Jun 2007
and if your not familiar with events

http://www.cpearson.com/excel/events.htm

also, if unfamiliar with the command for clearing the contents of cells,
some examples.

With Worksheets("Sheet1")
.Cells.clearContents
End With

With Worksheets("Sheet2")
.Range("A1,B9,C57").ClearContents
End With

--
Regards,
Tom Ogilvy


"Joost" wrote:

> Hello,
>
> Is it possible to clear cells when a workbook is closed with vba
> automatically.
> I can't figur it out who can help me
>
> Thanks
>
>
>

 
Reply With Quote
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      12th Jun 2007
Just to add,
Unless it is a single sheet workbook, the results might be more satisfying
if the range is qualified with a specific sheet name. Otherwise, the command
assumes the activesheet and success clearing a specific range on a specific
sheet in Thisworkbook (assuming that is the objective) might be thwarted by
the user.

--
Regards,
Tom Ogilvy


"Vasant Nanavati" wrote:

> A little shorter:
>
> Private Sub Workbook_BeforeClose(Cancel As Boolean)
> Range("A1:B100").ClearContents 'alter range to suit
> End Sub
>
> _____________________________________________________________________
>
>
> "Mike H" <(E-Mail Removed)> wrote in message
> news:0E5277AD-042F-4F4C-8392-(E-Mail Removed)...
> > Try this in the before_close workbook event:-
> >
> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > Set myRange = Worksheets("Sheet1").Range("A1:B100") '< Alter to suit
> > With myRange
> > .Select
> > .Clear
> > End With
> > ActiveWorkbook.Save
> > End Sub
> >
> > "Joost" wrote:
> >
> >> Hello,
> >>
> >> Is it possible to clear cells when a workbook is closed with vba
> >> automatically.
> >> I can't figur it out who can help me
> >>
> >> Thanks
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
=?Utf-8?B?TWlrZSBI?=
Guest
Posts: n/a
 
      12th Jun 2007
Success will also be thwarted if in the shorter version the user presses 'NO'
to save changes.

Macro - Something:- that does what you tell it to do and not what you want
it to do. Anonymous.


"Tom Ogilvy" wrote:

> Just to add,
> Unless it is a single sheet workbook, the results might be more satisfying
> if the range is qualified with a specific sheet name. Otherwise, the command
> assumes the activesheet and success clearing a specific range on a specific
> sheet in Thisworkbook (assuming that is the objective) might be thwarted by
> the user.
>
> --
> Regards,
> Tom Ogilvy
>
>
> "Vasant Nanavati" wrote:
>
> > A little shorter:
> >
> > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > Range("A1:B100").ClearContents 'alter range to suit
> > End Sub
> >
> > _____________________________________________________________________
> >
> >
> > "Mike H" <(E-Mail Removed)> wrote in message
> > news:0E5277AD-042F-4F4C-8392-(E-Mail Removed)...
> > > Try this in the before_close workbook event:-
> > >
> > > Private Sub Workbook_BeforeClose(Cancel As Boolean)
> > > Set myRange = Worksheets("Sheet1").Range("A1:B100") '< Alter to suit
> > > With myRange
> > > .Select
> > > .Clear
> > > End With
> > > ActiveWorkbook.Save
> > > End Sub
> > >
> > > "Joost" wrote:
> > >
> > >> Hello,
> > >>
> > >> Is it possible to clear cells when a workbook is closed with vba
> > >> automatically.
> > >> I can't figur it out who can help me
> > >>
> > >> Thanks
> > >>
> > >>
> > >>

> >
> >
> >

 
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
Before Cell Exit Brad Microsoft Excel Programming 2 13th May 2010 05:34 PM
Can't exit cell being edited =?Utf-8?B?RGFuRw==?= Microsoft Excel Crashes 0 14th Nov 2007 03:40 PM
How to move to 1st cell in next row after exit a particular cell. =?Utf-8?B?V2luZDU0U3VyZmVy?= Microsoft Excel Programming 4 17th Apr 2006 11:39 PM
How do I change cell color upon entry, and exit? =?Utf-8?B?RGVi?= Microsoft Excel Worksheet Functions 1 4th Aug 2005 09:48 AM
Run Macro on cell exit Kelly Microsoft Excel Programming 7 5th May 2004 09:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:17 AM.