单击某个单元格时,我遇到了以下用于生成msgbox的VBA:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("D4")) Is Nothing Then
MsgBox "Hello World"
End If
End If
End Sub
这很好用,但是立即添加另一个的语法是什么?即,单击不同的单元格以获取不同的消息。
谢谢
这是处理两个单元格的一种方法:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then
If Not Intersect(Target, Range("D4")) Is Nothing Then
MsgBox "Hello World"
End If
If Not Intersect(Target, Range("F5")) Is Nothing Then
MsgBox "Goodby World"
End If
End If
End Sub
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句