I'm having some trouble trying to make this code work:
Private Sub Worksheet_Change(ByVal Target As Range)
Static ZeroFlag As Boolean
Dim KeyCells As Range
Set KeyCells = Range("B29")
On Error Resume Next
Set KeyCells = Application.Union(KeyCells, KeyCells.Precedents)
On Error GoTo 0
If Not Application.Intersect(Target, KeyCells) Is Nothing Then
If (Range("B29").Value <= 0) Xor ZeroFlag Then
MsgBox IIf(ZeroFlag, "Not zero", "zero")
ZeroFlag = Not (ZeroFlag)
End If
End If
End Sub
The thing is, the alert only shows when I change the values from the sheet where "B29" is but i need the alert to show up when I alter values from other sheets too.
For example: The "B29" cell is located on sheet A and is the result of A1-A2, A2 is getting its value from cell A1 at the B sheet but the alert is only showing if I alter cell A2 from the A sheet and not A1 from B sheet.
What can I do to make it work?
When I first started do work on this code i looked like this and it work when I altered the value from diferents sheets
Private Sub Worksheet_Calculate()
If Range("B29").Value <= "0" Then
MsgBox "Zero"
Else
MsgBox "Not Zero"
End If End Sub
But this code does not have the rules that i need.
Until the cell is bigger than 0 the alert does not show up, when the value is below 0 the alert shows "Zero" and as long as the value remains below 0 it stop showing, the moment the value is bigger than 0 the alert shows " Not Zero" as long as the value remains above 0 it stop showing.
What can I do to make it work?
Thanks