LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Worksheet_Change Event "Circular Reference"

Cheers for that Bob! Excellent!


-----Original Message-----
Vyyk,

Disabling events will stop the automatic triggering of

any subsequent
events. This can be done with
Application.EnableEvents = False

Just make sure you reset to True on exit from the

procedure.

As a further fail-safe, it is best to trap any errors,

so that you don't
bomb out of the procedure with events disabled. So in

summary, the procedure
would look like

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim v As Variant
Static x As Long

Application.EnaableEvents = False
On Error Goto ws_exit

x = x + 1

Select Case Target.Column
Case 1
With Target
.Font.Bold = True
.Offset(0, 1).Font.Bold = False
.Offset(0, 1) = Target * 2
End With
Case 2
v = Application.Caller
Debug.Print v
With Target
.Font.Bold = True
.Offset(0, -1).Font.Bold = False
.Offset(0, -1) = Target / 2
End With
End Select

Application.StatusBar = x

ws_exit:
Application.EnableEvents = True

End Sub


--
HTH

-------

Bob Phillips
... looking out across Poole Harbour to the Purbecks


"Vyyk Drago" wrote in message
...
Hi,

I have an interesting problem. I have a worksheet

where
I want to be able to make the action of changing the
value of cell A1, cause the value of B1 display double
the value of A1. If I type a value in B1 I want A1 to
display half the value of B1 (Actually the calculation

is
much more complicated, but just for testing purposes

any
relational calculation will do.) When I use the
Worksheet_Change event, it captures the value changes

in
one cell and runs the calculation, but that then

changes
the value of the adjacent cell which then runs the code
again, etc. I have found that after approx. 220
iterations it finally stops, but this can cause loads

of
other problems for me.

To put it simply, how can I tell the worksheet_change
event not to fire if code run from that event causes
other cells to change. Here is a sample of my code

below:

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)

Dim v As Variant
Static x As Long

x = x + 1

Select Case Target.Column
Case 1
With Target
.Font.Bold = True
.Offset(0, 1).Font.Bold = False
.Offset(0, 1) = Target * 2
End With
Case 2
v = Application.Caller
Debug.Print v
With Target
.Font.Bold = True
.Offset(0, -1).Font.Bold = False
.Offset(0, -1) = Target / 2
End With
End Select

Application.StatusBar = x

End Sub

Please note that the x variable is used to check how

many
times this event runs before it stops and I have no

idea
on how to use the Caller property. I thought that

maybe
it could be used to see if the event called itself and
therefore be used to tell it to stop.

Please help...this is driving me nuts.
Many thanks
Vyyk



.

 
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
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell Steve Kay Excel Discussion (Misc queries) 2 August 8th 08 01:54 AM
change cell event using circular reference - not VBA! Dan Excel Worksheet Functions 3 June 17th 08 03:26 PM
change cell event using circular reference Dan Excel Worksheet Functions 3 June 17th 08 10:32 AM
Circular reference error when trying to keep a "running Tally" CrisT Excel Discussion (Misc queries) 0 June 26th 07 06:00 PM
How do I make a "Worksheet_Change event" to show any changes to cells? [email protected] Excel Worksheet Functions 2 April 26th 06 06:28 PM


All times are GMT +1. The time now is 11:31 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"