ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro run from if then function (https://www.excelbanter.com/excel-programming/362293-macro-run-if-then-function.html)

Ram

Macro run from if then function
 
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



Ram

Macro run from if then function
 
I wasn't using uppercase B in the Target. Address. Now it's working fine.


"ram" wrote:

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



Ivan Raiminius

Macro run from if then function
 
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



All times are GMT +1. The time now is 07:23 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com