![]() |
Check if a range is inside another
Hi,
What options do I have to check if the target range of a SelectionChange event is inside another? Rafael |
Check if a range is inside another
Hi Rafael
This will give you a start ;-) Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Application.Intersect(Target, Range("myrng")) Is Nothing Then MsgBox "ranges intersect" Else MsgBox "Ranges Don't intersect!" End If End Sub Rafael Sobral wrote in message ... Hi, What options do I have to check if the target range of a SelectionChange event is inside another? Rafael |
Check if a range is inside another
Loomah showed how to check if they intersect by at least one cell although I
would assume contain means that all cells in target are within the range of myrng . To see if target is totally contained in the range Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Application.Union(Target, Range("myrng")).Address = Range("myrng").Address Then MsgBox "Target is contained within or equal to myrng" Else MsgBox "Target not contained within or equal to myrng" End If End Sub you can use Intersect and compare the address to Target.address -- Regards, Tom Ogilvy "Rafael Sobral" wrote in message ... Hi, What options do I have to check if the target range of a SelectionChange event is inside another? Rafael |
All times are GMT +1. The time now is 10:32 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com