PC Review


Reply
Thread Tools Rate Thread

How to Stop Worksheet_Change event from running during code execution

 
 
rob nobel
Guest
Posts: n/a
 
      6th Mar 2004
I'm sorry If I've asked this before but I can't find an answer to it.

I have the following 2 events in a worksheet module....
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

I run some codes, either in UserForms or general procedures that make
changes to this worksheet.
Q. Is there a way to by-pass those two events somehow?

As an example I have a uf that comes up if a cell is selected in that sheet.
So I need those worksheet_Change events to work at that point.
But then, the uf does some stuff like inputing data, clearing data, etc.
that I don't want those worksheet_Change events always to be checking for
any changes.

Part of one of the uf codes....

Private Sub OKButton_Click()
With Application
.Calculation = xlManual
End With
'Clear existing entry in cols P:R
ActiveSheet.Unprotect
ActiveCell.Offset(0, 3).Resize(1, 3).ClearContents

When it gets to this last line, the Worksheet_Change procedure is invoked as
obviously a change has happened (ClearContents).

Rob


 
Reply With Quote
 
 
 
 
Dave Peterson
Guest
Posts: n/a
 
      6th Mar 2004
application.enableevents = false
'do a bunch of stuff to change selection or values
application.enableevents = true



rob nobel wrote:
>
> I'm sorry If I've asked this before but I can't find an answer to it.
>
> I have the following 2 events in a worksheet module....
> Private Sub Worksheet_Change(ByVal Target As Excel.Range)
> Private Sub Worksheet_SelectionChange(ByVal Target As Range)
>
> I run some codes, either in UserForms or general procedures that make
> changes to this worksheet.
> Q. Is there a way to by-pass those two events somehow?
>
> As an example I have a uf that comes up if a cell is selected in that sheet.
> So I need those worksheet_Change events to work at that point.
> But then, the uf does some stuff like inputing data, clearing data, etc.
> that I don't want those worksheet_Change events always to be checking for
> any changes.
>
> Part of one of the uf codes....
>
> Private Sub OKButton_Click()
> With Application
> .Calculation = xlManual
> End With
> 'Clear existing entry in cols P:R
> ActiveSheet.Unprotect
> ActiveCell.Offset(0, 3).Resize(1, 3).ClearContents
>
> When it gets to this last line, the Worksheet_Change procedure is invoked as
> obviously a change has happened (ClearContents).
>
> Rob


--

Dave Peterson
(E-Mail Removed)
 
Reply With Quote
 
 
 
 
rob nobel
Guest
Posts: n/a
 
      6th Mar 2004
Aww, I'm such a dunce! I knew I would have seen that b4.
Works great. Thanks Dave.

Rob

"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> application.enableevents = false
> 'do a bunch of stuff to change selection or values
> application.enableevents = true
>
>
>
> rob nobel wrote:
> >
> > I'm sorry If I've asked this before but I can't find an answer to it.
> >
> > I have the following 2 events in a worksheet module....
> > Private Sub Worksheet_Change(ByVal Target As Excel.Range)
> > Private Sub Worksheet_SelectionChange(ByVal Target As Range)
> >
> > I run some codes, either in UserForms or general procedures that make
> > changes to this worksheet.
> > Q. Is there a way to by-pass those two events somehow?
> >
> > As an example I have a uf that comes up if a cell is selected in that

sheet.
> > So I need those worksheet_Change events to work at that point.
> > But then, the uf does some stuff like inputing data, clearing data, etc.
> > that I don't want those worksheet_Change events always to be checking

for
> > any changes.
> >
> > Part of one of the uf codes....
> >
> > Private Sub OKButton_Click()
> > With Application
> > .Calculation = xlManual
> > End With
> > 'Clear existing entry in cols P:R
> > ActiveSheet.Unprotect
> > ActiveCell.Offset(0, 3).Resize(1, 3).ClearContents
> >
> > When it gets to this last line, the Worksheet_Change procedure is

invoked as
> > obviously a change has happened (ClearContents).
> >
> > Rob

>
> --
>
> Dave Peterson
> (E-Mail Removed)



 
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
Run VBA code only worksheet change, but don't trigger worksheet_change event based on what the code does ker_01 Microsoft Excel Programming 6 3rd Oct 2008 09:45 PM
Combine 2 codes from WorkSheet_Change & WorkSheet _SelectionChange to ONLY WorkSheet_Change Corey Microsoft Excel Programming 2 17th Dec 2006 10:59 PM
Can I stop code in a Worksheet_Change event with a Worbook_Deactivate event code? Ronaldo Microsoft Excel Programming 0 17th Nov 2004 06:37 AM
Re: worksheet_change vs. calculate, and worksheet_change not running Tom Ogilvy Microsoft Excel Programming 1 14th Jul 2003 02:51 AM
worksheet_change vs. calculate, and worksheet_change not running Ross Microsoft Excel Programming 0 13th Jul 2003 04:27 PM


Features
 

Advertising
 

Newsgroups
 


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