Resolving a Circular Reference

sdruley

Well-known Member
Joined
Oct 3, 2010
Messages
557
Office Version
  1. 365
Platform
  1. Windows
I have been struggling for days trying to find the source of a circular reference. I tried the following code but it just sits there doing nothing. Can anyone find the glitch in this code or perhaps give me a better tool?

Code:
Sub FindCircRefs()
      
       Set Source = ActiveSheet.Range("study")
       ' Get source information.
       Sourcesheet = ActiveSheet.Name
       
       Sheets.Add
       ' Get destination information.
       destsheet = ActiveSheet.Name
       destrange = ActiveCell.Address
       ' Return to source.
       Worksheets(Sourcesheet).Activate
       RowCount = 0
       ' Trap for error in "result", indicating no circular reference.
       On Error GoTo notcircular


       ' Loop through every used cell in source.
       For Each Item In Source
           ' Check to see if cell contains a formula.
           If Left(Item.Formula, 1) = "=" Then
               ' If cell intersects with precedents, cell has circular
               ' reference.
               result = Intersect(ActiveSheet.Range(Item.Address), _
                   ActiveSheet.Range(Item.Precedents.Address))


               Worksheets(destsheet).Range(destrange).Offset(RowCount, _
                   0).Value = Item.Address(False, False)


               Worksheets(destsheet).Range(destrange).Offset(RowCount, _
                   1).Value = "'" & Item.Formula


               RowCount = RowCount + 1
               ' Skip to here if not circular.
skipitem:
           End If
           Next
       Exit Sub


   ' If error in "result", go here.
notcircular:
       ' Skip cells that do not contain circular references.
      Resume skipitem
   End Sub
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
There's a couple options. From the Excel Ribbon, choose Formulas, Error Checking, Circular References.

From VBA you can code

Set BadCell = Worksheets("Sheet1").CircularReference

Which will select the first cell with a circular reference.
 
Upvote 0
Thank you gentlemen for your help. I guess I don't have a circular reference after all.


There's a couple options. From the Excel Ribbon, choose Formulas, Error Checking, Circular References.

From VBA you can code

Set BadCell = Worksheets("Sheet1").CircularReference

Which will select the first cell with a circular reference.
 
Upvote 0
Hi Guys,

I've removed my ribbon and there is no shortcut key for Error Checking in regard to finding the Circular Reference, that I can find.

I've tried the vba code above to search for my Circular Reference and no luck either.

Is there another vba code that can find a Circular Reference?

Thanks,
pinaceous
 
Upvote 0

Forum statistics

Threads
1,217,134
Messages
6,134,844
Members
449,893
Latest member
des378

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