none
VB.Net Excel range that is an intersection of two ranges RRS feed

  • Question

  • I am writing a VB.NET addin for Excel in Visual Studio, and I need to get a range that is the intersection of two other ranges. I can't find the VB.NET language that does this. I would guess it would look something like this:

    Dim range1 as Excel.Range = ActiveSheet.UsedRange
    Dim range2 as Excel.Range = Application.Selection
    Dim rangeISect as Excel.Range 
    
    rangeIsect = INTERSECT(range1,range2)
    
    
    

    But this doesn't work.  I can get range1 and range2 fine, but can't get the intersection of these two.  Can anyone provide me with the right terms for VB.NET?

    Gina


    Gina


    • Edited by Gina1111 Friday, May 1, 2015 8:54 PM
    Friday, May 1, 2015 8:53 PM

Answers

  • This works if I used this:

    rangeISect = Globals.ThisAddIn.Application.Intersect(range1, range2)
    
    


    Gina

    • Marked as answer by Gina1111 Friday, May 1, 2015 9:08 PM
    Friday, May 1, 2015 9:08 PM

All replies

  • This works if I used this:

    rangeISect = Globals.ThisAddIn.Application.Intersect(range1, range2)
    
    


    Gina

    • Marked as answer by Gina1111 Friday, May 1, 2015 9:08 PM
    Friday, May 1, 2015 9:08 PM
  • Hi Gina,

    I am glad that you have solved the problem and thanks for sharing us the solution here, so it would be helpful for other members who get the same issue.

    Best Regards,

    Edward


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, May 4, 2015 2:19 AM