Worksheet.UsedRange Property (2007 System)
Gets a Range object that represents all the cells that have contained a value at any time.
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 ReadOnly Property UsedRange As Range
'Usage
Dim instance As Worksheet
Dim value As Range
value = instance.UsedRange
[BrowsableAttribute(false)]
public Range UsedRange { get; }
[BrowsableAttribute(false)]
public:
property Range^ UsedRange {
Range^ get ();
}
public function get UsedRange () : Range
Property Value
Type: Range
A Range object that represents all the cells that have contained a value at any time.
Remarks
A used range includes any cell that has ever been used. For example, if cell A1 contains a value, and then you delete the value, then cell A1 is considered used. In this case, the UsedRange property will return a range that includes cell A1.
Examples
The following code example uses the UsedRange property to select the range of used cells on a worksheet. The example first sets the range of cells from A1 to C3 on the current worksheet to the value 23. If the worksheet is visible, then the example uses the UsedRange property to select the Range of used cells.
This example is for a document-level customization.
Private Sub SelectUsedRange()
Me.Activate()
Me.Range("A1", "C3").Value2 = 23
If Me.Visible = Excel.XlSheetVisibility.xlSheetVisible Then
Me.UsedRange.Select()
End If
End Sub
private void SelectUsedRange()
{
this.Activate();
this.Range["A1", "C3"].Value2 = 23;
if (this.Visible == Excel.XlSheetVisibility.xlSheetVisible)
{
this.UsedRange.Select();
}
}
.NET Framework Security
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.