Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 检查和跟踪空单元格时出错_Excel_Vba - Fatal编程技术网

Excel 检查和跟踪空单元格时出错

Excel 检查和跟踪空单元格时出错,excel,vba,Excel,Vba,在Excel中,可以找到引用空单元格的公式 比如说 A1=1 B1=空 C1=0.5 D1=A1+B1+C1 D1将正确计算值为1.5 但是,错误检查将确定公式D1中存在错误,并且可以为此单元格绘制箭头 如果用户有空单元格的引用,我需要提醒用户 当我尝试使用该功能录制自己时,我得到了以下信息 With Application.ErrorCheckingOptions .EvaluateToError = False .TextDate = False .NumberAsT

在Excel中,可以找到引用空单元格的公式

比如说

A1=1

B1=空

C1=0.5

D1=A1+B1+C1

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

如果用户有空单元格的引用,我需要提醒用户

当我尝试使用该功能录制自己时,我得到了以下信息

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

ActiveSheet.ClearArrows
仅检查空单元格的选项设置正确,但“跟踪”功能的实际执行完全被忽略。是否有任何方法可以使这种情况自动发生,然后检查测试结果


函数是“公式选项卡”“错误检查”“引用空单元格的公式”“跟踪空单元格”

这里是一个VBA方法,用于检查引用空单元格的公式。这不仅会告诉您它是哪个公式,还会告诉您哪个单元格是空的

为了验证这一点,在表1中的单元格A1中输入以下公式

=F1+G1+H1
=A1*D5
保持H1为空,填充F1和G1

在单元格A5中,输入以下公式

=F1+G1+H1
=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
运行宏时,您将在即时窗口中看到输出

快照

试试看
=IF(COUNTA(A1:A3),“ok”,“error”)来查找数组中的空格,如果通过了,则可以执行任何其他需要执行的操作。

我想在我的大型电子表格的每一页上运行公式>错误检查,但我也找不到任何VBA代码来执行它

我想到的最好的方法是使用Goto>Special选择错误,这需要错误处理来忽略在没有发现错误时发生的错误(并且它不适用于#N/A常量)

Dim r As范围
出错时继续下一步
集合r=ActiveCell.SpecialCells(xlCellTypeFormulas,xlErrors)
如果错误号0和错误号1004,则停止
错误转到0
如果不是的话,r什么都不是
如果r.计数>0,则
r、 挑选
如果结束
如果结束

如果出现除1004“未找到任何单元格”以外的错误,则除了中断宏之外,我还没有解决此问题。

我可能错了,但我怀疑是否有直接调用跟踪空错误的方法。如果一段代码告诉您公式中的哪个单元格是空的,会有帮助吗?