[Solved] - Can i check if 2 range intersect?

Hi,
I have 2 scopes (such as "C1:G10" AND "D6:Q3")
Is there any function to check whether these two regions meet?  (they can be in any where)
I want to be able to detect if they contain at least one common cell.
code:   if app.intersect(range ("C1:G10"), range ("D6:Q3")) then print (true)
Thanks you!

3 Replies

SK Shamini Kiruba Sobers Syncfusion Team May 13, 2020 10:47 AM UTC

Hi Khanh Dang, 

Greetings from Syncfusion. 

Kindly make use of the following code snippet to achieve your requirement. 

Code snippet: 

Dim intersectRange As IRange = worksheet.IntersectRanges(worksheet.Range("C1:G10"), worksheet.Range("D3:Q6")) 
If intersectRange IsNot Nothing Then 
    Console.WriteLine("true") 
End If 

You can see that we have changed the range “D6:Q3” into “D3:Q6”. Microsoft Excel automatically detects the ranges given in incorrect order and converts them into correct range format. Currently, XlsIO is not supported with such automatic conversion to correct range format. So we suggest you to supply the range in correct format (ie. range starting from minimum row/column value to maximum row/column value) like “D3:Q6”. 

Kindly try the above code and let us know if it helps. 

Regards, 
Shamini


TG The GridLock May 13, 2020 03:36 PM UTC

Thanks Shamini, this will help me soon.


SK Shamini Kiruba Sobers Syncfusion Team May 14, 2020 05:02 AM UTC

Hi Khanh Dang, 

We are glad that you are happy with the solution. 

Regards, 
Shamini 


Loader.
Up arrow icon