NamedRange.DirectPrecedents Property

Gets a Microsoft.Office.Interop.Excel.Range that represents the range containing all the direct precedents of the NamedRange control.

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

Syntax

'Declaration
ReadOnly Property DirectPrecedents As Range
Range DirectPrecedents { get; }

Property Value

Type: Microsoft.Office.Interop.Excel.Range
A Microsoft.Office.Interop.Excel.Range that represents the range containing all the direct precedents of the NamedRange control.

Remarks

This property can return a multiple selection (a union of Microsoft.Office.Interop.Excel.Range objects) if there is more than one dependent.

This property only works on the active sheet and cannot trace remote references.

Examples

The following code example creates a NamedRange and sets a reference in cell C2 to refer to cell C1, and then sets a reference in the NamedRange to refer to cell C2. The code example then uses the DirectPrecedents property to select the direct precedent of the NamedRange, which is cell C2.

This example is for a document-level customization.

Private precedentRange As Microsoft.Office.Tools.Excel.NamedRange

Private Sub SelectDirectPrecedents()
    precedentRange = Me.Controls.AddNamedRange( _
        Me.Range("B1"), "precedentRange")

    Me.Range("C1").Value2 = 1710
    Me.Range("C2").Value2 = "=C1" 

    Me.precedentRange.Value2 = "=C2" 
    Me.precedentRange.DirectPrecedents.Select()
End Sub
Microsoft.Office.Tools.Excel.NamedRange precedentRange;
private void SelectDirectPrecedents()
{
    precedentRange = this.Controls.AddNamedRange(
        this.Range["B1"], "precedentRange");

    this.Range["C1"].Value2 = 1710;
    this.Range["C2"].Value2 = "=C1";

    this.precedentRange.Value2 = "=C2";
    this.precedentRange.DirectPrecedents.Select();
}

.NET Framework Security

See Also

Reference

NamedRange Interface

Microsoft.Office.Tools.Excel Namespace