错误检查和跟踪空白单元格

在Excel中,可以find引用空单元格的公式。

例如

A1 = 1

B1 =空

C1 = .5

D1 = A1 + B1 + C1

D1将正确计算该值为1.5但是,错误检查将确定公式D1中存在错误,并且可以为该单元格绘制一个箭头。

我需要提醒用户,如果他们有一个空单元格的引用。

当我尝试使用functionlogging自己,我得到这个

With Application.ErrorCheckingOptions .EvaluateToError = False .TextDate = False .NumberAsText = False .InconsistentFormula = False .OmittedCells = False .UnlockedFormulaCells = False .ListDataValidation = False .InconsistentTableFormula = False End With ActiveSheet.ClearArrows 

仅检查空单元的选项已正确设置,但“跟踪”function的实际执行完全被忽略。 有什么办法可以自动发生,然后检查testing的结果?

function是“公式选项卡”“错误检查”“涉及空单元格的公式”“跟踪空单元格”

这里是一个VBA方法来检查公式参考空单元格。 这不仅会告诉你它是哪个公式,而且哪个单元格是空的。

为了testing这个,在Sheet1中,Cell A1把这个公式

 =F1+G1+H1 

保持H1为空并填充F1和G1

在A5单元格中,input这个公式

 =A1*D5 

保持单元格D5空。

现在将这个代码粘贴到一个模块中。

 Option Explicit Sub Sample() Dim ws As Worksheet Dim RngFormulas As Range, fCell As Range, _ DPrcd As Range, aCell As Range Set ws = Sheets("Sheet1") With ws On Error Resume Next Set RngFormulas = .Cells.SpecialCells(xlCellTypeFormulas) On Error GoTo 0 If Not RngFormulas Is Nothing Then For Each fCell In RngFormulas On Error Resume Next Set DPrcd = fCell.DirectPrecedents On Error GoTo 0 If Not DPrcd Is Nothing Then For Each aCell In DPrcd If IsEmpty(aCell.Value) Then Debug.Print aCell.Address & " in " & _ fCell.Formula & " is empty" End If Next End If Next End If End With End Sub 

当你运行这个macros时,你会在即时窗口看到输出。

快照

在这里输入图像描述

尝试= IF(COUNTA(A1:A3),“ok”,“error”)在数组中find空格,如果通过,那么你可以做任何其他需要做的事情。

我想在我的大电子表格的每个页面上运行Formulas> Error Checking,但是我也找不到任何VBA代码来执行它。

我想出的最好的办法是使用Goto> Special来select错误,这需要error handling来忽略没有发现错误时发生的错误(并且它不适用于#N / A常量)。

 Dim r As Range On Error Resume Next Set r = ActiveCell.SpecialCells(xlCellTypeFormulas, xlErrors) If Err.Number <> 0 And Err.Number <> 1004 Then Stop On Error GoTo 0 If Not r Is Nothing Then If r.Count > 0 Then r.Select End If End If 

如果1004以外的错误“找不到单元格”。 发生的时候,我还没有为这个macros而努力。