Run/call a macro when value in cell A5 changes

A

Arno

Hello,

I need a macro to run/call another macro when values in cell A5 changes.

Can you please advise if the syntax below is correct.

So far I cannot get it to work ....

Thank you !! Arno


Sub Last()
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$5" Then
Graph2
End If
End Sub
 
D

Don Guillett

Should work OK if you put in the sheet module where cell a5 resides. Right
click sheet tab>view code>copy/paste there without the sub last() line

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$5" Then graph2
End Sub

Sub graph2()
MsgBox "Works Just fine"
End Sub
 
M

Mike H

Hi,

Providing you have a sub called Graph2 then this should work

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$5" Then
Graph2
End If
End Sub

Mike
 
A

Arno

I tried to copy and past as suggested but I get this msg: Ambiguous name
detected: Worksheet_change.

Do you have an idea why ?

Thank you so far !
 
D

Dave Peterson

You only get one worksheet_Change event for each sheet.

And you have at least two of them.

You'll have to combine them into a single routine.
 
A

Arno

Hi Mike,
More than one object in the same scope may have elements with the same name.
The identifier conflicts with another identifier or requires qualification.

The macro you sent me is in conflict with another which is similar. Pls see
below
Can you help to adjust:


Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "$A$3"

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Call Master
End With
End If
 
M

Mike H

Hi,

It would have helped if you posted all your code. Not tested but this should
combine them.

Private Sub Worksheet_Change(ByVal Target As Range)
Const WS_RANGE As String = "$A$3"

On Error GoTo ws_exit
Application.EnableEvents = False

If Not Intersect(Target, Me.Range(WS_RANGE)) Is Nothing Then
With Target
Call Master
End With
End If

ws_exit:
Application.EnableEvents = True
If Target.Address = "$A$5" Then
Graph2
End If
End Sub

Mike
 
A

Arno

Mike,

I have no words to thank you ! I worked staight away !!!

This was the last step of a difficult xls file with about 20 macros. Now
everything work ! Thank you so much again!!!!!!

Thank to you Dave as well !!!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top