【问题标题】:A formula in this worksheet contains one or more invalid references error此工作表中的公式包含一个或多个无效引用错误
【发布时间】:2015-08-16 13:13:23
【问题描述】:

我多次使用相同的代码,只对行号进行少量更改来创建相同类型的图表。但是在绘制图表的工作表上会弹出以下消息框。

“此工作表中的公式包含一个或多个无效引用。验证您的公式是否包含有效的路径、工作簿、区域名称和单元格引用。”

如何摆脱这个消息框?我尝试使用

 Application.DisplayAlertS = False

但它不起作用。

【问题讨论】:

  • 快速查找所有无效引用的方法:F5 -> 特殊,选择“公式”,然后仅检查“错误”。如果它选择多个单元格将它们的背景更改为红色,然后将它们一个一个修复

标签: excel charts vba


【解决方案1】:

您将需要找到公式并更改链接或断开链接,十分之九,您将有一个单元格引用指向不再存在(或不存在)的工作表或工作簿't open),如果您在脚本中使用.delete,这种情况会发生更多

很遗憾,Excel 无法轻松找到此链接,您可以查看数据选项卡并查看现有连接,然后断开它们。但以前的经验一直没有这个工作。

您也可以尝试this macro from Allen Wyatt,它会检查您的工作表并创建一个包含潜在错误列表的新工作表公式错误

Sub CheckReferences()
' Check for possible missing or erroneous links in
' formulas and list possible errors in a summary sheet

  Dim iSh As Integer
  Dim sShName As String
  Dim sht As Worksheet
  Dim c, sChar As String
  Dim rng As Range
  Dim i As Integer, j As Integer
  Dim wks As Worksheet
  Dim sChr As String, addr As String
  Dim sFormula As String, scVal As String
  Dim lNewRow As Long
  Dim vHeaders

  vHeaders = Array("Sheet Name", "Cell", "Cell Value", "Formula")
  'check if 'Summary' worksheet is in workbook
  'and if so, delete it
  With Application
    .ScreenUpdating = False
    .DisplayAlerts = False
    .Calculation = xlCalculationManual
  End With

  For i = 1 To Worksheets.Count
    If Worksheets(i).Name = "Summary" Then
      Worksheets(i).Delete
    End If
  Next i

  iSh = Worksheets.Count

  'create a new summary sheet
    Sheets.Add After:=Sheets(iSh)
    Sheets(Sheets.Count).Name = "Summary"
  With Sheets("Summary")
    Range("A1:D1") = vHeaders
  End With
  lNewRow = 2

  ' this will not work if the sheet is protected,
  ' assume that sheet should not be changed; so ignore it
  On Error Resume Next

  For i = 1 To iSh
    sShName = Worksheets(i).Name
    Application.Goto Sheets(sShName).Cells(1, 1)
    Set rng = Cells.SpecialCells(xlCellTypeFormulas, 23)

    For Each c In rng
      addr = c.Address
      sFormula = c.Formula
      scVal = c.Text

      For j = 1 To Len(c.Formula)
        sChr = Mid(c.Formula, j, 1)

        If sChr = "[" Or sChr = "!" Or _
          IsError(c) Then
          'write values to summary sheet
          With Sheets("Summary")
            .Cells(lNewRow, 1) = sShName
            .Cells(lNewRow, 2) = addr
            .Cells(lNewRow, 3) = scVal
            .Cells(lNewRow, 4) = "'" & sFormula
          End With
          lNewRow = lNewRow + 1
          Exit For
        End If
      Next j
    Next c
  Next i

' housekeeping
  With Application
    .ScreenUpdating = True
    .DisplayAlerts = True
    .Calculation = xlCalculationAutomatic
  End With

' tidy up
  Sheets("Summary").Select
  Columns("A:D").EntireColumn.AutoFit
  Range("A1:D1").Font.Bold = True
  Range("A2").Select
End Sub

【讨论】:

  • 谢谢@Jake。我要试试这个。同时,你能帮我解决另一个问题bit.ly/1J9ndmu(我正在寻找第二部分的解决方案-传奇部分)
【解决方案2】:

我正在搜索,因为我在使用空图表时遇到了同样的问题,并且弹出了同样错误的消息。由于这里没有人对此问题有任何解决方案,而我发现了一个解决方案,我在这里分享我的情况下解决此问题的方法。

我简化了所有命名范围的公式,例如:

Named range = Offset(Plan1!A1;0;0;8-CountBlank(Other named range))

我将要计算的最后一部分 "8-CountBlank(Other named range)" 放在工作表中,并将其替换为范围公式中的结果。如果图表完全为空,则不再显示弹出错误。我希望有一天能帮助遇到同样问题的人。

【讨论】:

  • 图表中的引用也会产生这个错误,你已经浏览了数据,看看你在哪里看到#REF
【解决方案3】:

接受的解决方案对我不起作用,但我可以使用这个免费的 Excel 插件立即解决

只需下载并按照此处的说明进行操作: http://www.manville.org.uk/software/findlink.htm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-08
    • 2017-08-14
    • 1970-01-01
    • 1970-01-01
    • 2017-07-12
    • 2019-07-23
    • 1970-01-01
    相关资源
    最近更新 更多