Detect cell change (formula)

TheWennerWoman

Active Member
Joined
Aug 1, 2019
Messages
303
Office Version
  1. 365
Platform
  1. Windows
Hello,

I have a formula in cell J2 that is
Code:
=EXACT (A2, B2)

I want to detect if this changes from TRUE to FALSE or vice versa.

I have tried
Code:
Private Sub Worksheet_Calculate()
Static MyOldVal

If Range("J2").Value <> MyOldVal Then
MsgBox "Hello"
MyOldVal = Range("J2").Value
End If
End Sub

However this always fires (wrongly) the first time something is entered on the sheet and J2 recalculates. After that, it works perfectly. How can I stop it triggering the first time?

Thanks for reading.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi. What about a worksheet change event focused on cells A2 and B2?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim kcell As Range: Set kcell = Range("A2:B2")
Static MyOldVal

If Not Application.Intersect(kcell, Range(Target.Address)) Is Nothing Then
    If Range("J2").Value <> MyOldVal Then
        MsgBox "Hello"
        MyOldVal = Range("J2").Value
    End If
End If
End Sub
 
Upvote 0
Hi. What about a worksheet change event focused on cells A2 and B2?

VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim kcell As Range: Set kcell = Range("A2:B2")
Static MyOldVal

If Not Application.Intersect(kcell, Range(Target.Address)) Is Nothing Then
    If Range("J2").Value <> MyOldVal Then
        MsgBox "Hello"
        MyOldVal = Range("J2").Value
    End If
End If
End Sub
Apologies, A2 and B2 are also formulae.
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top