问题
I'm using C# to create a Excel Add-In.
How can I check if selected(or cell represented by a range in code) is in specyfic range. For example how to check if cell $P$5 is in range $A$1:$Z$10
回答1:
Use Application.Intersect
, like this (in VBA)
Sub TestIntersect()
Dim MyRange As Range
Dim TestRange As Range
Set TestRange = [$A$1:$Z$10]
Set MyRange = [P5]
If Not Application.Intersect(MyRange, TestRange) Is Nothing Then
Debug.Print "the ranges intersect"
End If
End Sub
来源:https://stackoverflow.com/questions/12767320/checking-if-selected-cell-is-in-specific-range