Macro run from if then function

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The code below only runs if the Target.Address = "$A$1" . If i change the
Target.Address to ="$B$1" and make a change to cell B1 the macro won't run.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$A$1" Then
Application.Run "Test_Output_file!Macro1"
End If
End Sub

Thanks in advance for any help
 
Hi,

you are comparing two strings, so you have to be sure that they will be
the same (if target.address is "$B$1" and in your condition you have
Target.Address = "$b$1", then these two strings don't match).

There are many ways how to do it:

If Target.Address = range("b1").address Then

or

if not intersect(target,range("b1") is nothing then

for example.
Regards,
Ivan
 

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

Back
Top