View Single Post
  #6   Report Post  
Posted to microsoft.public.excel,microsoft.public.excel.misc,microsoft.public.excel.programming
Frank Kabel Frank Kabel is offline
external usenet poster
 
Posts: 3,885
Default Changing the contents of a cell... dynamically?

Hi
quite easy. Without this line each time you change the cell A10 the
event gets triggered again. So the line .Value=.value-25 will invoke
this procedure again. With disabling application events the macro just
performs its tasks (and re-enables the events after the processing)

Frank

Shatin wrote:
Hello,

Can you guys please explain to me why you need the line:

Application.EnableEvents = False

When I commented out the line, when I entered 100 into the cell, I
got the result 5500 rather than 75. What has happened?

Rightclick the sheet tab. Choose "view code". Paste this in:

Private Sub Worksheet_Change(ByVal Target As Range)
With Target(1)
If .Address = "$A$10" Then
If IsNumeric(.Formula) Then
Application.EnableEvents = False
.Value = .Value - 25
Application.EnableEvents = True
End If
End If
End With
End Sub

--
HTH. Best wishes Harald
Followup to newsgroup only please

"Friendly Indián" skrev i melding
...
I am wanting to do something that I don't know if it is
possible. Here is the scenario...

Say cell A10 gets data (numbers) entered into it, for this
example lets say 100, after the focus moves from the cell I want
25 to be automatically subtracted from the number so that it is
actually is 75. How can I do this if it is possible? Thanks.

--

Please reply to newsgroup so we can all learn from you
knowledge.
Private emails will not be answered.

Friendly Indián