ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Determining if two ranges overlap (https://www.excelbanter.com/excel-programming/291621-determining-if-two-ranges-overlap.html)

Marky[_2_]

Determining if two ranges overlap
 
Hi,

I am trying to write a piece of code that will enable me to validate
two ranges to determine whether or not they overlap. I can determine
fairly easily if one is contained wholly within the other but not if
they only partially overlap. Any suggestions on how I could approach
this problem would be appreciated!

Thanks,
Mark


---
Message posted from http://www.ExcelForum.com/


Frank Kabel

Determining if two ranges overlap
 
Hi
try
If Intersect(range1, range2) Is Nothing Then 'no overlapping
--
Regards
Frank Kabel
Frankfurt, Germany

Hi,

I am trying to write a piece of code that will enable me to validate
two ranges to determine whether or not they overlap. I can determine
fairly easily if one is contained wholly within the other but not if
they only partially overlap. Any suggestions on how I could approach
this problem would be appreciated!

Thanks,
Mark


---
Message posted from http://www.ExcelForum.com/



Bob Phillips[_6_]

Determining if two ranges overlap
 
Marky,

Intersect will do it

If Not Intersect(rng1, rng2) Is Nothing Then
...

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Marky " wrote in message
...
Hi,

I am trying to write a piece of code that will enable me to validate
two ranges to determine whether or not they overlap. I can determine
fairly easily if one is contained wholly within the other but not if
they only partially overlap. Any suggestions on how I could approach
this problem would be appreciated!

Thanks,
Mark


---
Message posted from http://www.ExcelForum.com/




Marky[_3_]

Determining if two ranges overlap
 
Thanks guys, that worked a treat!

Mar

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Determining if two ranges overlap
 
Mark,

As an aside, what is your code for determining if one is contained within
the other?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Marky " wrote in message
...
Thanks guys, that worked a treat!

Mark


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 07:33 PM.

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