简体   繁体   中英

VBA Excel - If a certain value in the column matches my criteria then display a message

I want to create a macro that keeps running in the background while i am working on the excel sheet.

Function: if a certain cell in an entire column = Now() then display a message box.

Can someone please share the code for this?

Put this in your worksheet module

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
' for a certain column - in this case G
    Dim Arr
        Arr = Split(Target.Address, "$")
        If Arr(1) = "G" Then
            Beep
            MsgBox "You have selected column G..."
        End If

' for a certain row - in this case 2
    If Right(Target.Address, 2) = "$2" Then
        Beep
        MsgBox "You have selected Row 2..."
    End If

' for a certain cell - in this case A3
    If Target.Address = "$A$3" Then
        Beep
        MsgBox "You have selected Cell A3..."
    End If


End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM