We help IT Professionals succeed at work.

Cell Value Change

151 Views
Last Modified: 2012-05-05
Hello
Trying to setup a code when value of a12 is changed, a message box will appear saying "the value has changed"
Comment
Watch Question

Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Commented:
Hi,
Is this value of 12 in any particular cell?

You can use the Worksheet_Change event for this. Assuming the cell to be A1

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Address <> "$A$1" Then Exit Sub
    If Target.Value <> 12 Then MsgBox "The value has changed", vbCritical
End Sub

Open in new window

Commented:
Hi,
Sorry, I misread your post. The cell is obviously A12.

byundtMechanical Engineer
CERTIFIED EXPERT
Most Valuable Expert 2013
Top Expert 2013

Commented:
If this were strictly Excel, then you could use a Worksheet_Change sub. The one posted below will respond to user changes to cell A12. If cell A12 contains a formula, then the sub will also respond to any changes to inputs to that formula--provided that the inputs are located on the same worksheet. If the inputs are on a different worksheet, the message won't be displayed if they change.

To install a sub in the code pane for a worksheet:
1) Right-click the sheet tab for the worksheet
2) Choose View Code from the resulting pop-up
3) Paste the suggested code in the resulting module sheet
4) ALT + F11 to return to the worksheet

If the above procedure doesn't work, then you need to change your macro security setting. To do so, open the Tools...Macro...Security menu item. Choose Medium, then click OK.
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rg As Range, targ As Range
Set targ = [A12]
On Error Resume Next
Set rg = targ.Precedents
Set targ = Union(targ, rg)
On Error GoTo 0
If Not Intersect(Target, targ) Is Nothing Then MsgBox "Cell A12 has changed"
End Sub

Open in new window

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.