Results 1 to 3 of 3

Thread: Run macro based on cell value

  1. #1

    Run macro based on cell value



    Register for a FREE account, and/
    or Log in to avoid these ads!

    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

  2. #2
    Conjurer Simi's Avatar
    Join Date
    Feb 2012
    Location
    Utah, USA
    Posts
    187
    Articles
    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

  3. #3
    Quote Originally Posted by Simi View Post
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •