次の方法で共有


WorksheetBase.UsedRange Property

Definition

Gets a Range object that represents all the cells that have contained a value at any time.

public:
 property Microsoft::Office::Interop::Excel::Range ^ UsedRange { Microsoft::Office::Interop::Excel::Range ^ get(); };
public Microsoft.Office.Interop.Excel.Range UsedRange { get; }
member this.UsedRange : Microsoft.Office.Interop.Excel.Range
Public ReadOnly Property UsedRange As Range

Property Value

A Range object that represents all the cells that have contained a value at any time.

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 Microsoft.Office.Interop.Excel.Range of used cells.

This example is for a document-level customization.

private void SelectUsedRange()
{
    this.Activate();
    this.Range["A1", "C3"].Value2 = 23;
    if (this.Visible == Excel.XlSheetVisibility.xlSheetVisible)
    {
        this.UsedRange.Select();
    }
}
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

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.

Applies to