此工作表中的公式包含一个或多个无效的引用错误

我使用相同的代码很多次,行号的变化很less,以创build相同types的图表。 但是,在绘制图表的工作表上popup以下消息框。

“此工作表中的公式包含一个或多个无效的引用。请validation您的公式包含有效的path,工作簿,范围名称和单元格引用。

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

Application.DisplayAlertS = False 

但它不起作用。

你将需要find公式,并改变链接或打破它,十次中有九次,你将有一个单元格引用到工作表或工作簿不再存在(或未打开),如果您在脚本中使用.delete ,则会发生这种情况

不幸的是,excel不容易find这个链接,你可以查看数据选项卡,看看现有的连接,然后打破它们。 但以前的经验一直没有这个工作。 但是,您可以尝试使用这个macros来检查您的工作表,并创build一个包含所有潜在错误列表的新工作表。

 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 

我正在search,因为我有与空图表相同的问题,并popup相同的错误消息。 由于没有人在这里解决了这个问题,我发现一个解决了这个问题,我在这里分享这个问题的解决scheme在我的情况。

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

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

我把最后一部分"8-CountBlank(Other named range)"计算在工作表中,并在结果的范围公式中将其replace。 如果图表完全是空的,则不会再显示popup错误。 我希望有一天能帮助别人解决同样的问题。