Envor Theron
Envor Theron

Reputation: 1

Run popup message in protected excel sheet when the value of two cells are equal

I want to confirm with a popup message and sound effect in a protected Excel 2010 worksheet when the values of two cells are the same. I have tried this formula in data validation:

IF(D4=D5,beepnow(),"")

but it does not run. Can anyone assist with the formula or a VBA code replacement instead? Thanks!

Upvotes: 0

Views: 107

Answers (2)

user7392562
user7392562

Reputation:

If you go to the VB COde Window, select the relevant sheet, you can have the following

Private Sub Worksheet_Change(ByVal Target As Range)

If (Range("D4:D4").Cells(1, 1)) = Range("D5:D5").Cells(1, 1))  Then
MsgBox ("Hi")

End If
End Sub

The worksheet activate will run the code when you select this sheet.

The Worksheet_change will run the code when you make a change in this sheet.

IF you want to have the check only when D4/D5 is modified

If Target.Address = "$D$4" Or Target.Address = "$D$5" Then
If (Range("D4:D4").Cells(1, 1)) = Range("D5:D5").Cells(1, 1))  Then
MsgBox ("Hi")
End If
End If

Upvotes: 1

J_Lard
J_Lard

Reputation: 1103

Here's a program that will run whenever you change to the worksheet... which may get pretty annoying... You should get the idea though and be able to modify it to fit your needs.

Private Sub Worksheet_Activate()
If Range("D4").Value = Range("D5").Value Then
    Beep
    MsgBox "Equal", vbInformation, "Check"
End If

End Sub

You should just be able to copy and paste it into your worksheet class.

Upvotes: 1

Related Questions