Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Kicking off macro if data in cell changes

Is there a way to kick off a macro if the value of a specific cell changes?
The tricky part is that this particular cell's is driven by a formula (in
other words, the user does not manually enter data in this cell).
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default Kicking off macro if data in cell changes

Try pasting this into the code for the worksheet in question:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Range("A1").Precedents, Target) Is Nothing Then
MsgBox "Something Preceding Range A1 was changed"
End If
End Sub

Charles

dumb and frustrated wrote:
Is there a way to kick off a macro if the value of a specific cell changes?
The tricky part is that this particular cell's is driven by a formula (in
other words, the user does not manually enter data in this cell).


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Kicking off macro if data in cell changes

The calculate event. You would have to use a static variable to record the
value of the cell each time, then compare it to the current value, take
action if appropriate, store the current value over the old value.

--
Regards,
Tom Ogilvy


"dumb and frustrated" wrote:

Is there a way to kick off a macro if the value of a specific cell changes?
The tricky part is that this particular cell's is driven by a formula (in
other words, the user does not manually enter data in this cell).

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Kicking off macro if data in cell changes

If you don't mind, could you write me a small example? I understand your
idea...but I'm having trouble creating it. (I'm 4 months old in VBA).


"Tom Ogilvy" wrote:

The calculate event. You would have to use a static variable to record the
value of the cell each time, then compare it to the current value, take
action if appropriate, store the current value over the old value.

--
Regards,
Tom Ogilvy


"dumb and frustrated" wrote:

Is there a way to kick off a macro if the value of a specific cell changes?
The tricky part is that this particular cell's is driven by a formula (in
other words, the user does not manually enter data in this cell).

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Kicking off macro if data in cell changes

right click on the sheet tab and select view code.

In the left dropdown at the top of the resulting module, select Worksheet
and in the right dropdown select calculate.

You will get a declaration like this in the module

Private Sub Worksheet_Calculate()

End Sub

add you code there

-----------------------------------------
Private Sub Worksheet_Calculate()
Static oldval as Variant

On Error goto ErrHandler

if not isempty(oldval) then
if Range("B9").Value < oldval then
Application.EnableEvents = False
mymacro
end if
end if
oldval = Range("B9").Value

ErrHandler:
Application.EnableEvents = True
End Sub
------------------------------------

mymacro would be the name of the subroutine that contains the code you want
to run. It should be in a general module (insert=module in the VBE)

--
Regards,
Tom Ogilvy

"dumb and frustrated" wrote:

If you don't mind, could you write me a small example? I understand your
idea...but I'm having trouble creating it. (I'm 4 months old in VBA).


"Tom Ogilvy" wrote:

The calculate event. You would have to use a static variable to record the
value of the cell each time, then compare it to the current value, take
action if appropriate, store the current value over the old value.

--
Regards,
Tom Ogilvy


"dumb and frustrated" wrote:

Is there a way to kick off a macro if the value of a specific cell changes?
The tricky part is that this particular cell's is driven by a formula (in
other words, the user does not manually enter data in this cell).

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
"Kicking Out" Inactive Users Mike The Newb Excel Discussion (Misc queries) 11 August 9th 07 05:16 PM
"Kicking Out" Inactive users 2 PaulW Excel Discussion (Misc queries) 0 August 31st 06 03:43 PM
Kicking Out Selective (Not all) Inactive Users Mike The Newb Excel Discussion (Misc queries) 2 August 31st 06 02:54 PM
Writing a macro to copy first cell down until next cell has data Gerald[_2_] Excel Programming 1 August 10th 05 10:06 PM
enter data in cell which will start macro to move data to sheet2 Tommy Excel Discussion (Misc queries) 0 May 12th 05 05:00 PM


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