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

时间:2019-04-23 17:28:54

标签: excel vba

我创建了一个宏,如果该单元格为空,则在空单元格中放置“ 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

结束子

1 个答案:

答案 0 :(得分: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