Macro Is Not Working on Base of Cell Value

killlarboy

New Member
Joined
Oct 10, 2016
Messages
9
Hello All,

Kindly solve my code maybe i did something wrong i want to run a macro automatically on base of cell A2

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("$A2:$A2")) And Value = "1" Then
Application.Run "Macro1"
End If
End Sub
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Here would be a way:

Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range

Set rng = Intersect(Target, Range("A2"))
If Not rng Is Nothing Then
    If rng.Value = 1 Then
        Application.Run "Macro1"
    End If
End If

End Sub
 
Upvote 0
What do you mean? Use the same thing on 5 sheets? Or just run 5 macros?
 
Upvote 0
The below mentioned code is working only but if the cell is blank if want to trigger macro using the cell value

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A2:A2")) Is Nothing Then
Application.Run "Macro1"
End If
End Sub
 
Upvote 0
The following code is working only.. if the cell A2 is blank
now my question is it is possible to run macro automatically if the cell A2 value is equal to 1 because the one you coded that is not working for me. only below mentioned code is working

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("A2:A2")) Is Nothing Then
Application.Run "Macro1"
End If
End Sub
 
Upvote 0
Is it equal to the number 1, or the text value 1?
You can usually tell by how the value is justified in the cell. If you have not explicitly selected a custom formatting justification selection, numbers are right-justified (by default), and text is left-justified (by default).
 
Upvote 0
Change sheet events don't get triggered by formulas.Try this mod on the code supplied by steve the fish'
Code:
Private Sub Worksheet_Change(ByVal Target As Range)

Dim rng As Range

Set rng = Intersect(Target, Range("[COLOR=#ff0000]D[/COLOR]2"))
If Not rng Is Nothing Then
    If rng.Value = 1 Then
        Application.Run "Macro1"
    End If
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,692
Messages
6,126,226
Members
449,303
Latest member
grantrob

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top