如何修复宏仍然在#value之后继续

问题描述 投票:0回答:1

我创建了一个宏,如果单元格为空白,我将“N / A”放在空单元格中。我通过多个工作表来完成这项工作。我遇到的问题是一些工作表中有一些公式,导致“#value!”然后导致我的宏发生错误。反正在那周围,我尝试了一些东西,但它不起作用。

Sub test()

Dim i As Integer
Dim r As Long, c As Long
'Dim ws As Worksheet

Application.ScreenUpdating = False
For i = 6 To Worksheets.Count


    For c = 1 To 14
    For r = 5 To 1000
        If Sheets(i).Cells(r, c) = "" Or "#value!" Then
        Sheets(i).Cells(r, c).Value = "N/A"
        End If

    Next r
    Next c
Next i

结束子

excel vba
1个回答
2
投票

首先测试错误:

IF iserror(Sheets(i).Cells(r, c)) Then
    Sheets(i).Cells(r, c).Value = "N/A"
ElseIF Sheets(i).Cells(r, c) = "" Then
    Sheets(i).Cells(r, c).Value = "N/A"
End If
© www.soinside.com 2019 - 2024. All rights reserved.