View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.programming
Jim May Jim May is offline
external usenet poster
 
Posts: 430
Default EnableEvent On Change

Tom, thanks for the revised code.
If there is an error then the code jumps to the
ws_err: code line and proceeds to the very next line
Application.EnableEvents = TRUE << which is an (OK) redundent
<< statement
setting the EnableEvents
<< to True
before ending the code.
But if there is an error (Prompted for in line 2 of code)
then all the remaining lines 3 thru the last line of the code runs, right?
when it gets to the line ws_err: << it just reads it and proceeds to the
next line
Application.EnableEvents = TRUE

For the above reason I don't see the illogic of Bob's modified code as it
seems
to do the same thing.

Could you speak to my
So what stops it dead (from further repeating/calculating) when I enter 100
in cell
D6?



"Tom Ogilvy" wrote in message
...
Events got disabled because of a slight logic problem.

To start them run this macro:

Sub StartEvents()
Appliction.EnableEvents = True
End Sub

fix the code to look like this:

Private Sub Worksheet_Change(ByVal Target As Range)
On Error Goto ws_err
Application.EnableEvents = False
If Not Intersect(Target, Range("D5:G10")) Is Nothing Then
Target.Value = Target.Value * 1.06
End If
ws_err:
Application.EnableEvents = True
End Sub


--
Regards,
Tom Ogilvy

"Jim May" wrote in message
news:RB5Yd.58764$%U2.37993@lakeread01...
Bob:
Thanks;
What logic am I missing here? After EVERY - CHANGE this Macros runs,

right?
So what stops it dead (from further calculating) when I enter 100 in

cell
D6?
Jim

"Bob Phillips" wrote in message
...
Private Sub Worksheet_Change(ByVal Target As Range)
On Error Goto ws_err
Application.EnableEvents = False
If Intersect(Target, Range("D5:G10")) Is Nothing Then
Exit Sub
Else
Target.Value = Target.Value * 1.06
End If

ws_err:
Application.EnableEvents = True
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Jim May" wrote in message
news:Sj5Yd.58600$%U2.51909@lakeread01...
It's obvious i haven't understood this situation where a change,

causes
a
change, which causes a change -- of course this is happening due to

my
line:
Target.Value = Target.Value * 1.06
If I enter 100 in cell D6 - the system goes wild and produces

102,461.64
versus my expected 106.
Help with this would be appreciated.
TIA,

Private Sub Worksheet_Change(ByVal Target As Range)
If Intersect(Target, Range("D5:G10")) Is Nothing Then
Exit Sub
Else
Target.Value = Target.Value * 1.06
End If
End Sub