Macro to alert me when a cell changes value - pop-up warning - EXCEL

I want to create a macro to alert me when a cell value changes. The cells in this column can be either OVER or UNDER. I would like to write code to alert me through a popup (Message: "Cell A is baptized under (above)") when the value changes.

Thanks,

Patrick

+4
source share
1 answer

You need to connect to Worksheet_Change event .
Something like this should start you up:

 Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) If Target.Value = "OVER" Then MsgBox "Cell " & Target.Address & " crosses OVER" ElseIf Target.Value = "UNDER" Then MsgBox "Cell " & Target.Address & " crosses UNDER" End If End Sub Sub just_testing() Dim mycell As Object Set mycell = ActiveSheet.Cells(1, 1) Call Worksheet_Change(mycell) End Sub 

Using this code, changing the value of cell A1 to OVER (case sensitive!) Will print the message "Cell $ A $ 1 crosses OVER."


Edit based on additional information provided by OP:
For automatic sheet changes, you need to use the Worksheet_Calculate event (example below). For some strange reason, Excel seems like you have =NOW() anywhere in the worksheet for Worksheet_Calculate to actually run.

 Private Sub Worksheet_Calculate() Dim mycell As Object Set mycell = ActiveSheet.Cells(1, 1) If mycell.Value = "OVER" Then MsgBox "Cell " & mycell.Address & " crosses OVER" ElseIf mycell.Value = "UNDER" Then MsgBox "Cell " & mycell.Address & " crosses UNDER" End If End Sub 
+1
source

Source: https://habr.com/ru/post/1308703/


All Articles