Run a macro if a certain value is entered in a cell

N

nickystan

Hi,
I want to have it so that on a column if a certain value is entered in any
of the cells then a message is displayed to tell them to do something else.
I want to be able to run a macro if the value is entered.
 
D

Dave Peterson

You can use a worksheet event ...

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("a1")) Is Nothing Then Exit Sub
If Target.Value = "" Then Exit Sub

MsgBox "You just changed: " & Target.Address(0, 0) & vbLf & _
". Now don't forget to..."

End Sub

Right click on the worksheet tab that should have this behavior. Select view
code and paste this into the code window that just opened.

Change A1 to the address of the cell you want to check.
 
N

nickystan

Thanks - that was really helpful

Dave Peterson said:
You can use a worksheet event ...

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range("a1")) Is Nothing Then Exit Sub
If Target.Value = "" Then Exit Sub

MsgBox "You just changed: " & Target.Address(0, 0) & vbLf & _
". Now don't forget to..."

End Sub

Right click on the worksheet tab that should have this behavior. Select view
code and paste this into the code window that just opened.

Change A1 to the address of the cell you want to check.
 
Top