I found the following code online and slightly altered it for my use. I don't remember the source or I would give credit. The code loops through all sheets in the Workbook and finds circular references. This works perfectly but I need it to show a message if no circular references were found.
I added a message box at the end of this code but it fires every time a reference is found. If I have multiple circular references then I need it to fire only after the last reference is found. Any and all help is greatly appreciated.
VBA Code:
Sub FindCircularReferences(control As IRibbonControl)
Dim ws As Worksheet
Dim rng As Range
Dim msg As String
For Each ws In ThisWorkbook.Worksheets
Set rng = ws.CircularReference
If Not rng Is Nothing Then
rng.Parent.Select
rng.Select
msg = "Circular reference found on sheet " & ws.Name & _
" in cell " & rng.Address(0, 0) & _
" with formula: " & vbLf & rng.Formula
MsgBox msg, vbCritical, "Circular Reference Found"
Exit For
End If
Next ws
MsgBox "Nothing Found", vbInformation, "Circular Reference" ' my added code
End Sub
I added a message box at the end of this code but it fires every time a reference is found. If I have multiple circular references then I need it to fire only after the last reference is found. Any and all help is greatly appreciated.