If Workbook Contains a Circular Reference then

bajlewis

New Member
Joined
Nov 1, 2011
Messages
12
Hello,

I'm trying to get something like this to work (simplified for example, I know excel already warns me):

Code:
Sub CircTEST()

If ActiveWorkbook.CircularReferences.Count > 0 Then
    MsgBox ("Circ Ref")
 Else
    MsgBox ("NO Circ Ref")
  End If
End Sub

Didn't think it would be too difficult however I can't find the answer. The part that doesn't work is this.. "ActiveWorkbook.CircularReferences.Count > 0" it doesn't evaluate to boolean.

Thanks
-Bart
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
The circularReference object is a member of the workSHEET group, not workBOOK..
And it reterns a RANGE object of the first (top left) cell with a circular.
It returns NOTHING if there are no circulars on the sheet

Try this

Code:
Sub test()
If ActiveSheet.CircularReference Is Nothing Then
    MsgBox "no circulars"
Else
    MsgBox "there is a circular in " & ActiveSheet.CircularReference.Address
End If
End Sub
 
Upvote 0
Thanks for the quick reply! I suppose I can set a loop through the sheets in the book to check them all.



To further the challenge...

When on another sheet in the book (one that doesn't contain a circular reference) the Status Bar (lower left) displays a warning that there are circular references... I was wondering if there is a way to utilize that indicator to invoke a warning despite what sheet you are on. What part of the application generates this and how to I get at it?
 
Upvote 0
I am only aware of the worksheets("Sheetname").CircularReference Object..

To loop through the sheets, you could do something like

<font face=Error: Key or Value Not Found.><SPAN style="color:#00007F">Sub</SPAN> test()<br><SPAN style="color:#00007F">Dim</SPAN> ws <SPAN style="color:#00007F">As</SPAN> Worksheet<br><SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> ws <SPAN style="color:#00007F">In</SPAN> Worksheets<br>    <SPAN style="color:#00007F">If</SPAN> <SPAN style="color:#00007F">Not</SPAN> ws.CircularReference <SPAN style="color:#00007F">Is</SPAN> <SPAN style="color:#00007F">Nothing</SPAN> <SPAN style="color:#00007F">Then</SPAN><br>        MsgBox "there is a circular in " & ws.Name & "!" & ws.CircularReference.Address<br>    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN><br><SPAN style="color:#00007F">Next</SPAN> ws<br><SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN></FONT>
 
Upvote 0
I do have a correction to which cell is referred to by the circularreference object..
I originally said it would be the first (top left) cell with a circular.
But that's not correct

The verbage of the help files is
Returns a Range object that represents the range containing the first circular reference on the sheet

After testing, First actually means the first(chronologically) circular that was created.
Not necessarily first in Top/left order.
 
Upvote 0

Forum statistics

Threads
1,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top