ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   cell range (https://www.excelbanter.com/excel-programming/405538-cell-range.html)

ranswert

cell range
 
I need to write a procedure that will run only when a selected cell is within
a range of cells. How do I identify if it is within a range?

joel

cell range
 
Use intersect

Worksheets("Sheet1").Activate
Set isect = Application.Intersect(Range("rg1"), Range("rg2"))
If isect Is Nothing Then
MsgBox "Ranges do not intersect"
Else
isect.Select
End If

"ranswert" wrote:

I need to write a procedure that will run only when a selected cell is within
a range of cells. How do I identify if it is within a range?


ranswert

cell range
 
Thanks I 'll give that a try

"Joel" wrote:

Use intersect

Worksheets("Sheet1").Activate
Set isect = Application.Intersect(Range("rg1"), Range("rg2"))
If isect Is Nothing Then
MsgBox "Ranges do not intersect"
Else
isect.Select
End If

"ranswert" wrote:

I need to write a procedure that will run only when a selected cell is within
a range of cells. How do I identify if it is within a range?


[email protected]

cell range
 
Hi

If not intersect(Selection, myRange) is nothing then
'do something
end if

where myRange is your Range of Cells.
e.g. Set myRange = ActiveSheet.Range("A2:B6")

If you only want one cell selected then

If Selection.Count = 1 then
If not intersect(Selection, myRange) is nothing then
'do something
end If
End If

regards
Paul

On Feb 4, 3:04*pm, ranswert
wrote:
I need to write a procedure that will run only when a selected cell is within
a range of cells. *How do I identify if it is within a range?




All times are GMT +1. The time now is 11:37 PM.

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