WorksheetBase.CircularReference Property

Definition

Gets a Range object that represents the range containing the first circular reference on the sheet, or gets null if there is no circular reference on the sheet.

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

Property Value

A Range object that represents the range containing the first circular reference on the sheet; null if there is no circular reference on the sheet.

Examples

The following code example creates a circular reference by setting the formulas of cells A1 and B1 to resolve to the value of each other. The example then uses the CircularReference property to report whether the worksheet has a circular reference.

This example is for a document-level customization.

private void HasCircularReference()
{
    this.Range["A1"].Formula = "=B1";
    this.Range["B1"].Formula = "=A1";

    if (this.CircularReference == null)
    {
        MessageBox.Show("This worksheet has no circular references");
    }
    else
    {
        MessageBox.Show("The worksheet has a circular reference at: " +
            this.CircularReference.get_Address(Excel.XlReferenceStyle.xlA1));
    }
}
Private Sub HasCircularReference()
    Me.Range("A1").Formula = "=B1"
    Me.Range("B1").Formula = "=A1"

    If Me.CircularReference Is Nothing Then
        MsgBox("This worksheet has no circular references")
    Else
        MsgBox("The worksheet has a circular reference at: " & _
            Me.CircularReference.Address( _
            ReferenceStyle:=Excel.XlReferenceStyle.xlA1))
    End If
End Sub

Remarks

The circular reference must be removed before calculation can proceed.

Applies to