Link to home
Start Free TrialLog in
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"
ASKER CERTIFIED SOLUTION
Avatar of nutsch
nutsch
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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

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

Avatar of 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