Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5696
  • Last Modified:

Excel VBA Run macro when cell value changes from a formula

I have a data validation list in cell B3.  I want to run a macro when this value changes.  I have a formula in cell P2 that is =B3, so whatever the value in B3 is what shows in P2.  I have the below vba code, hoping my clearA macro will run, but it is not working.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Target, Range("P2")) Is Nothing Then
If Target.Address = "$P$2" Then
clearA
End If
End Sub

Open in new window

0
jnikodym
Asked:
jnikodym
1 Solution
 
Saqib Husain, SyedEngineerCommented:
Try

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$B$3" Then
clearA
End If
End Sub
0
 
Shanan212Commented:
Try this

Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$B$3" Then
MsgBox "Hi"
End If

End Sub

Open in new window

0
 
NorieData ProcessorCommented:
Instead of checking if P2 has changed check if B3 has changed.
Private Sub Worksheet_Change(ByVal Target As Range)
   If Not Intersect(Target, Range("B3")) Is Nothing Then

      clearA
   End If 

End Sub 

Open in new window

0
 
Saqib Husain, SyedEngineerCommented:
Does that mean that the first one does not work?
0
 
jnikodymAuthor Commented:
the Worksheet_SelectionChange part of your solution was causing an issue.  When i changed it to Worksheet_Change it worked.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now