Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Change event on single cell fires many times

I have the following code in a sheet module to capture the change event, when
the user changes cell contents:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$5" Then Call OtherProgram
End Sub

The problem is, when I edit cell E5 the program runs a long time, calling
the above routine over and over, presumably because my spreadsheet has many
formulas in it? Anyway, it seems to be looping a lot and it shouldn't. How
can I get it to stop this behaviour?

i.e. When the user edits E5 and presses Enter, it should run once. BTW, the
edited cell is not a formula, but contains a string. Many other cells are
linked to E5.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Change event on single cell fires many times

Hi XP,

I suspect that your code differs from that whhich you show.

However, typically, to avoid recursive calls to the event procedure try
something like:

'=============
Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo XIT
Application.EnableEvents = False
'Your code

XIT:
Application.EnableEvents = True
End Sub
'<<=============


---
Regards,
Norman



"XP" wrote in message
...
I have the following code in a sheet module to capture the change event,
when
the user changes cell contents:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$5" Then Call OtherProgram
End Sub

The problem is, when I edit cell E5 the program runs a long time, calling
the above routine over and over, presumably because my spreadsheet has
many
formulas in it? Anyway, it seems to be looping a lot and it shouldn't. How
can I get it to stop this behaviour?

i.e. When the user edits E5 and presses Enter, it should run once. BTW,
the
edited cell is not a formula, but contains a string. Many other cells are
linked to E5.

Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
XP XP is offline
external usenet poster
 
Posts: 389
Default Change event on single cell fires many times

Hi Norman, that did the trick thanks.

But my code does not differ: I copied it from my module...I'm curious, why
do you say you think it differs?

BTW, I will need to read your response tonight or tomorrow, I'm outta here!

Thanks again!

"Norman Jones" wrote:

Hi XP,

I suspect that your code differs from that whhich you show.

However, typically, to avoid recursive calls to the event procedure try
something like:

'=============
Private Sub Worksheet_Change(ByVal Target As Range)

On Error GoTo XIT
Application.EnableEvents = False
'Your code

XIT:
Application.EnableEvents = True
End Sub
'<<=============


---
Regards,
Norman



"XP" wrote in message
...
I have the following code in a sheet module to capture the change event,
when
the user changes cell contents:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$E$5" Then Call OtherProgram
End Sub

The problem is, when I edit cell E5 the program runs a long time, calling
the above routine over and over, presumably because my spreadsheet has
many
formulas in it? Anyway, it seems to be looping a lot and it shouldn't. How
can I get it to stop this behaviour?

i.e. When the user edits E5 and presses Enter, it should run once. BTW,
the
edited cell is not a formula, but contains a string. Many other cells are
linked to E5.

Thanks.




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Change event on single cell fires many times

Hi XP,


But my code does not differ: I copied it from my module...
I'm curious, why do you say you think it differs?


(1) Your code had the appearance of pseudo code

(2) I would not expect changes in formula dependent values to
fire the Worksheet_Change event

However, I am pleased that the conventional methodology of
deactivating and subsequently reactivating events has resolved
your problem.


---
Regards,
Norman


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Worksheet change event-single column jasminesy Excel Programming 2 July 17th 06 06:27 PM
Application.EnableEvents = true, but no event fires Wexler Excel Programming 0 October 19th 04 06:08 PM
worksheet_change event fires multiple times timconstan[_3_] Excel Programming 0 October 6th 04 03:59 PM
worksheet_change event fires multiple times timconstan[_2_] Excel Programming 1 October 5th 04 07:44 PM
worksheet_change event fires multiple times timconstan Excel Programming 1 October 5th 04 05:55 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"