View Single Post
  #6   Report Post  
Posted to microsoft.public.excel.misc
peyman peyman is offline
external usenet poster
 
Posts: 189
Default Accumulator Logic

Thanks a lot

"JE McGimpsey" wrote:

I can probably help:

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Address(False, False) = "D1" Then


We only operate on the accumulator if the changed range is the single
cell D1.

If IsNumeric(.Value) Then


Checks that the entry is a number

Application.EnableEvents = False


Since the next line will change the value in C1, if we don't disable
events, doing so will fire the Worksheet_Change code again. Disabling
events allows us to change the C1 value without triggering the _Change
event.

Range("c1").Value = Range("c1").Value + .Value


Adds the value in D1 to the value in C1

Application.EnableEvents = True


Turns on Event macros again.

End If
Next
End With
End Sub


In article ,
peyman wrote:

hi,
I'm using the following code taken from "McGimpsey & Associates" site and it
works nicely for me but I'm not able to undrestand how the code works and
what its logic is.can anybody explain to more about this codes,particulary
the line "Application.EnableEvents = False or true"?thanx.

Private Sub Worksheet_Change(ByVal Target As Excel.Range)
With Target
If .Address(False, False) = "D1" Then
If IsNumeric(.Value) Then
Application.EnableEvents = False
Range("c1").Value = Range("c1").Value + .Value
Application.EnableEvents = True
End If
Next
End With
End Sub