我想在创建excel表时创建一个在后台运行的宏。
功能:如果整列中的某个单元格= Now(),则显示一个消息框。
有人可以为此分享代码吗?
答案 0 :(得分:0)
将其放入工作表模块中
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