Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Worksheet.Range Property

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

Gets a Microsoft.Office.Interop.Excel.Range object that represents a cell or a range of cells.

Namespace:  Microsoft.Office.Tools.Excel
Assemblies:   Microsoft.Office.Tools.Excel (in Microsoft.Office.Tools.Excel.dll)
  Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)
Worksheet_RangeType Range { get; }

Property Value

Type: Microsoft.Office.Tools.Excel.Worksheet_RangeType
A Microsoft.Office.Interop.Excel.Range that represents a cell or a range of cells.

The Range property is intended to be used with the following parameters.

Parameter

Description

Cell1

The name of the range in A1-style notation in the language of the application. It can include the range operator (a colon), the intersection operator (a space), or the union operator (a comma). It can also include dollar signs, but they are ignored. You can use a local defined name in any part of the range. If you use a name, the name is assumed to be in the language of the application. This parameter is required.

Cell2

The cell in the lower-right corner of the range. Can be a Microsoft.Office.Interop.Excel.Range that contains a single cell, an entire column, an entire row, or it can be a string that names a single cell in the language of the application. This parameter is optional.

If you use the Range property without specifying any parameters, it will return a Worksheet_RangeType object that is not intended to be used directly from your code.

Optional Parameters

For information on optional parameters, see Optional Parameters in Office Solutions.

The following code example demonstrates different ways to use the Range property to access a single cell or multiple cells.

This example is for an application-level add-in.

private void CompareRangeUsage()
{                      
    Worksheet vstoWorksheet = Globals.Factory.GetVstoObject(
        this.Application.ActiveWorkbook.Worksheets[1]);
    // The following line of code specifies a single cell.
    vstoWorksheet.Range["A1"].Value2 = "Range 1";

    // The following line of code specifies multiple cells.
    vstoWorksheet.Range["A3", "B4"].Value2 = "Range 2";

    // The following line of code uses an Excel.Range for  
    // the second parameter of the Range property.
    Excel.Range range1 = vstoWorksheet.Range["C8"];
    vstoWorksheet.Range["A6", range1].Value2 = "Range 3";
}
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.