Worksheet.Range Property (2007 System)

Gets a Range object that represents a cell or a range of cells.

Namespace:  Microsoft.Office.Tools.Excel
Assembly:  Microsoft.Office.Tools.Excel.v9.0 (in Microsoft.Office.Tools.Excel.v9.0.dll)

Syntax

'Declaration
<BrowsableAttribute(False)> _
Public Overridable ReadOnly Property Range As Worksheet._RangeType
'Usage
Dim instance As Worksheet 
Dim value As Worksheet._RangeType 

value = instance.Range
[BrowsableAttribute(false)]
public virtual Worksheet._RangeType Range { get; }
[BrowsableAttribute(false)]
public:
virtual property Worksheet._RangeType^ Range {
    Worksheet._RangeType^ get ();
}
public function get Range () : Worksheet._RangeType

Property Value

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

Remarks

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 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 in Visual Basic.

If you attempt to use Range without specifying any parameters, Range will get a Worksheet._RangeType object that is part of the Visual Studio Tools for Office infrastructure and is not intended to be used directly from your code.

Optional Parameters

For information on optional parameters, see The Variable missing and Optional Parameters in Office Solutions.

Examples

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

This version is for a document-level customization.

Private Sub CompareRangeUsage()
    ' The following line of code specifies a single cell. 
    Me.Range("A1").Value2 = "Range 1" 

    ' The following line of code specifies multiple cells. 
    Me.Range("A3", "B4").Value2 = "Range 2" 

    ' The following line of code uses an Excel.Range for  
    ' the second parameter of the Range property. 
    Dim range1 As Excel.Range = Me.Range("C8")
    Me.Range("A6", range1).Value2 = "Range 3" 
End Sub
private void CompareRangeUsage()
{
    // The following line of code specifies a single cell. 
    this.Range["A1", missing].Value2 = "Range 1";

    // The following line of code specifies multiple cells. 
    this.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 = this.Range["C8", missing];
    this.Range["A6", range1].Value2 = "Range 3";
}

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

Private Sub CompareRangeUsage()
    Dim vstoWorksheet As Worksheet = _
        CType(Me.Application.ActiveWorkbook.Worksheets(1), Excel.Worksheet) _
        .GetVstoObject()
    ' 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. 
    Dim range1 As Excel.Range = vstoWorksheet.Range("C8")
    vstoWorksheet.Range("A6", range1).Value2 = "Range 3" 
End Sub
private void CompareRangeUsage()
{                      
    Worksheet vstoWorksheet = ((Excel.Worksheet)
        this.Application.ActiveWorkbook.Worksheets[1]).GetVstoObject();
    // The following line of code specifies a single cell.
    vstoWorksheet.Range["A1", missing].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", missing];
    vstoWorksheet.Range["A6", range1].Value2 = "Range 3";
}

.NET Framework Security

See Also

Reference

Worksheet Class

Worksheet Members

Microsoft.Office.Tools.Excel Namespace

Change History

Date

History

Reason

July 2008

Added a version of the code example for an application-level add-in.

SP1 feature change.