WorksheetBase.CircularReference Property
Gets a Range object that represents the range containing the first circular reference on the sheet, or gets nulla null reference (Nothing in Visual Basic) if there is no circular reference on the sheet.
Namespace: Microsoft.Office.Tools.Excel
Assembly: Microsoft.Office.Tools.Excel.v4.0.Utilities (in Microsoft.Office.Tools.Excel.v4.0.Utilities.dll)
Syntax
'Declaration
Public ReadOnly Property CircularReference As Range
public Range CircularReference { get; }
Property Value
Type: Range
A Range object that represents the range containing the first circular reference on the sheet; nulla null reference (Nothing in Visual Basic) if there is no circular reference on the sheet.
Remarks
The circular reference must be removed before calculation can proceed.
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 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
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));
}
}
.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.