How do I get an Excel range using row and column numbers in VSTO / C#?

Dan Crowther picture Dan Crowther · Feb 25, 2010 · Viewed 129.2k times · Source

I think the question sums it up. Given two integers for row and column or four integers for row and column for the two corners of a range, how do I get a range object for that range.

Answer

burnside picture burnside · Feb 25, 2010

Where the range is multiple cells:

Excel.Worksheet sheet = workbook.ActiveSheet;
Excel.Range rng = (Excel.Range) sheet.get_Range(sheet.Cells[1, 1], sheet.Cells[3,3]);

Where range is one cell:

Excel.Worksheet sheet = workbook.ActiveSheet;
Excel.Range rng = (Excel.Range) sheet.Cells[1, 1];