Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Excel VBA Run macro when cell value changes from a formula

Posted on 2013-01-18
5
Medium Priority
?
5,523 Views
Last Modified: 2013-01-18
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
Comment
Question by:jnikodym
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38793407
Try

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.Address = "$B$3" Then
clearA
End If
End Sub
0
 
LVL 13

Expert Comment

by:Shanan212
ID: 38793411
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
 
LVL 35

Accepted Solution

by:
Norie earned 2000 total points
ID: 38793413
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
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38793458
Does that mean that the first one does not work?
0
 

Author Comment

by:jnikodym
ID: 38793474
the Worksheet_SelectionChange part of your solution was causing an issue.  When i changed it to Worksheet_Change it worked.
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
If you need to forecast numbers -- typically for finance -- the Windows and Mac versions of Excel 2016 have a basket of tools to get the job done.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

610 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question