Thursday, April 19, 2012

Determine a Cell in Specified Range or Not

Double click any sheet in VBA Project Explorer and paste following code:

Private Sub Worksheet_SelectionChange(ByVal target As Range)
If Not Intersect(target, Range("myrange")) Is Nothing Then
MsgBox target.Address & "is in myrange"
Else
MsgBox target.Address & "is not in myrange"
End If
End Sub

No comments:

Post a Comment