Run macro based on cell value

Lukael

New member
Joined
Feb 9, 2014
Messages
21
Reaction score
0
Points
0
Hello,

I want to run a macro with msgbox ("This is correct!"), If A2 Cell has a value "KP". How can I do that ?


Please give me code for macro and Worksheet !


Regards, Luka
 

Simi

New member
Joined
Feb 10, 2012
Messages
190
Reaction score
0
Points
0
Location
Utah, USA
Excel Version(s)
Version 2002 Build 12527.20194
you can put this in the ThisWorkbook code.
It will trigger when the contents of cell A2 change

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Target.Row = 2 And Target.Column = 1 Then
        If Target.Value = "KP" Then
            MsgBox ("This is correct!")
        End If
    End If
End Sub
 

Lukael

New member
Joined
Feb 9, 2014
Messages
21
Reaction score
0
Points
0
you can put this in the ThisWorkbook code.
It will trigger when the contents of cell A2 change

Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
    If Target.Row = 2 And Target.Column = 1 Then
        If Target.Value = "KP" Then
            MsgBox ("This is correct!")
        End If
    End If
End Sub

thanks, It works fine !!1
 
Top