Avatar of ASOSWE
ASOSWE
 asked on

Cell Value Change

Hello
Trying to setup a code when value of a12 is changed, a message box will appear saying "the value has changed"
Web Languages and StandardsMicrosoft Excel

Avatar of undefined
Last Comment
byundt

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
nutsch

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
WJReid

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

WJReid

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

byundt

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

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23