公式审计 – 针对特定区域的错误检查

我想问一下,是否可以检查一个特定地区的不一致的公式。

在我的情况下,col D和col E包含不同的公式集。

我只是想确保E栏中的所有公式都是一致的。

有没有可能这样做?

这是一种方法。

假设你的工作表看起来像这样

在这里输入图像说明

现在将这个代码粘贴到一个模块中并运行。 它会告诉你哪些单元格有不一致的公式。 看下面的截图

我已经评论了代码,以便您不会有任何理解它的问题。 如果你只是问:)

 Option Explicit Sub GetInConsCells() Dim ws As Worksheet Dim rng As Range, cl As Range, errCells As Range Dim ErrorCells As String Dim lRow As Long '~~> Create a temp copy of the sheet ThisWorkbook.Sheets("Sheet1").Copy After:=Sheets(ThisWorkbook.Sheets.Count) Set ws = ActiveSheet With ws '~~> Clear Col D and Col F Contents .Range("D:D,F:F").ClearContents '~~> Find the last row of col E lRow = .Range("E" & .Rows.Count).End(xlUp).Row '~~> Set your range Set rng = Range("E1:E" & lRow) '~~> Check if the cells have inconsistent formulas For Each cl In rng If cl.Errors(xlInconsistentFormula).Value Then If errCells Is Nothing Then Set errCells = cl Else Set errCells = Union(cl, errCells) End If End If Next cl '~~> Display relevant message If Not errCells Is Nothing Then ErrorCells = errCells.Address MsgBox "Formulas in cells " & ErrorCells & " are inconsitent" Else MsgBox "All Formulas are consistent" End If End With '~~> Delete temp sheet Application.DisplayAlerts = False ws.Delete Application.DisplayAlerts = True End Sub 

在这里输入图像说明

假设您想要检查E列中的每个单元格的公式=SUM(A1:D1) ,只需input公式=(SUM(A1:D1)-E1在另一列,然后select列并过滤FALSE – 这会给你所有的公式有不同的结果!