cell range

  • Thread starter Thread starter ranswert
  • Start date Start date
R

ranswert

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?
 
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
 
Thanks I 'll give that a try

Joel said:
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top