Checking if selected cell is in specific range

耗尽温柔 提交于 2019-12-23 22:51:29

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!