Select a Range by a Cell

Hi,

Imagine I have a Excel.Range (A1:C5) named "Test1" and now, my activecell is located at B2, I'd like to know how I can select and retrieve the whole range "Test1" by a cell

This is not work: Range["B2", missing].CurrentRegion... What's the correct property

Thanks.



Answer this question

Select a Range by a Cell

  • balaiitm

    Here's one example that might help you:

    C#

  • RichardDKelly

    Hi Rufus,

    I think I have to clarify more initially. What I wnat to do is to select a range (such as 3 x 7) but my ActiveCell is just 1 cell (within that range), what's the correct property to select the "parent" range

    Thanks,

  • Grzegorz Gogolowicz MSFT

    Depending on how you named the range, you should be able to get the named ranges via the Worksheet.Names or Workbook.Names property. In your VSTO project, members should have been created for each of these named ranges to make things easier. With your ActiveCell, you should then be able to call the Application.Intersect method to see what the intersection between your active cell and a particular named range is. If the method returns a range, then you are in that particular named range. Otherwise, the method will return null and you are not in the named range.
  • foobish

    Hi Peter,

    To slect a range, try something like this:

    C#
    Range["A1", "C5"].Select();

    // Or, just use the name of the Range and call the select method:
    Test1.Select();

    Rufus



  • Select a Range by a Cell