+ Reply to Thread
Results 1 to 6 of 6

Eliminate Excel Circular Reference Warning

Hybrid View

  1. #1
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Eliminate Excel Circular Reference Warning

    Hi all. I am trying to disable or deactivate the formulas in several cells as part of the workbook close event and reactive them during the workbook open event. The formulas contain an intentional circular reference and I'm trying to convert them to a text string so they won't be recognized as a circular reference when the workbook is opened again until after I enable iteration as part of the open event, after which I want to convert the text strings back to formulas. The purpose of this is to avoid the circular reference warning when the workbook is opened by users. I continue to get an error message in my code at the cell.formula lines in both of my subs below. Any help would be appreciated!


    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    With Worksheets("sheet1").Range("B14:B2000")
    
        .cell.Formula = "'" & cell.Formula
    
    End With
    
    Application.Iteration = False
    
    End Sub

    Private Sub Workbook_Open()
    
        With Application
            .Iteration = True
            .MaxIterations = 1
        End With
      
    With Worksheets("sheet 1").Range("B14:B2000")
      
        .cell.Formula = Right(cell.Formula, Len(cell.Formula) - 1)
    
    End With
      
    End Sub

    Many thanks in advance.

  2. #2
    Valued Forum Contributor
    Join Date
    09-21-2003
    Location
    British Columbia , Canada
    MS-Off Ver
    03,07,10,13
    Posts
    727

    Re: Eliminate Excel Circular Reference Warning

    "Range" does not have a object, method or attribute called "cell" so you will get an error . "Range" and "Cells" is generally an either or situation .. either you refer to a cells by the "Cells" object OR the "Range" object.
    ... maybe this code would help ? ... it's format the cells so they are text or general ..

    Public Sub MakeText()
       With Worksheets("sheet 1").Range("B14:B2000")
        .NumberFormat = "@"
       End With
    End Sub
       
    Public Sub MakeRegular()
       With Worksheets("sheet 1").Range("B14:B2000")
        .NumberFormat = "General"
       End With
    End Sub

  3. #3
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Eliminate Excel Circular Reference Warning

    Thanks for your help and clarification. I have replaced my code with the subs you created and have run them in my Workbook_Open() and Workbook_BeforeClose subs as shown below. They change the number format back and forth as intended. However, this still does not prevent Excel from giving the Circular Reference Warning upon opening the workbook, which is my ultimate objective.

    When viewing the formulas in the formula bar after the cell format has been changed to "text" via the code, there is no evidence that the formula has been converted to a text string, which is what I may need to avoid the circular reference warning?


    Private Sub Workbook_BeforeClose(Cancel As Boolean)
    
    Call MakeText
    
    Application.Iteration = False
    
    End Sub
    Private Sub Workbook_Open()
    
        With Application
            .Iteration = True
            .MaxIterations = 1
        End With
      
    Call MakeRegular
      
    End Sub
    Again, thanks for your help.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2010, 2019
    Posts
    40,689

    Re: Eliminate Excel Circular Reference Warning

    Try this. In ThisWorkbook,

    Const sRng As String = "B14:B2000"
    
    Private Sub Workbook_Open()
        IterationOnOff Sheet1.Range(sRng), True
    End Sub
    
    Private Sub Workbook_BeforeClose(Cancel As Boolean)
        IterationOnOff Sheet1.Range(sRng), False
    End Sub
    ... replacing Sheet1 with the CodeName of the sheet of interest.

    In a code module,
    Sub IterationOnOff(r As Range, bOn As Boolean)
        With r
            If bOn Then
                Application.Iteration = True
                Application.MaxIterations = 1
                .NumberFormat = "General"
                .Formula = .Value
            Else
                .NumberFormat = "@"
                .Value = .Formula
                Application.Iteration = False
            End If
        End With
    End Sub
    Last edited by shg; 04-05-2011 at 07:52 PM. Reason: Took out the Select ...
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Eliminate Excel Circular Reference Warning

    Thanks Shg.

    I've added the suggested code and it was successful in eliminating the circular reference warning. But it also had an unintended consequence on the circular reference formulas in the worksheet by causing them to return a "0" value or deleting the formulas altogether.

    I've attached a sample worksheet with the imbedded code, the circular reference formulas, and an explanation of what I need to achieve. I'm sure there is a solution here that I'm just not seeing.

    Many thanks for the help!
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    02-09-2010
    Location
    California, USA
    MS-Off Ver
    Excel 2019
    Posts
    94

    Re: Eliminate Excel Circular Reference Warning

    Bump no response

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1