ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Is the active cell part of a named range (https://www.excelbanter.com/excel-programming/328042-active-cell-part-named-range.html)

Virginia

Is the active cell part of a named range
 
how do use VBA to determine whether or not the activecell is part of a range
named "Data"
i.e., range("Data") spans from A1:J50

how can i return true on
range("B5") is part os range("Data")
TIA.

Patrick Molloy

Is the active cell part of a named range
 
use the Intersect method

Sub Test()
msgbox IsInRange(Range("B5"),range("Data"))
End Sub

Function IsInRange(test as range, target as range) as Boolean
dim found as range
set found = Intersect(Test,target)
IsInRange = (NOT Found Is Nothing)
End Function

"Virginia" wrote in message
...
how do use VBA to determine whether or not the activecell is part of a
range
named "Data"
i.e., range("Data") spans from A1:J50

how can i return true on
range("B5") is part os range("Data")
TIA.





All times are GMT +1. The time now is 09:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com