在IF语法VBA中包含#N/A值 [英] Include #N/A value in IF syntax VBA

查看:252
本文介绍了在IF语法VBA中包含#N/A值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在代码中包含单元格中的#N/A值时遇到问题.在我的工作表中,我想消除单元格的内容,因为它的值为0或#N/A,但是我不知道为#N/A编写VBA代码.

I have a problem including in my code the #N/A value in the cell. In my sheet, I want to eliminate the cell's content is the its value is either 0 or #N/A, but i don't know to write the VBA code for the #N/A.

这是对我有用的代码,但是遇到#N/A单元格时仍然给出错误.

This is the code that works for me, but it still gives an error when it encounters the #N/A cells.

For Each value In Sheets("Comments").Range("C2:Y600")
    If value = 0 Or value = "#N/A" Then
        value = " "
    End If
Next

推荐答案

而不是测试值是否测试单元格 IsNA

Instead of testing for the value test if the cell IsNA

Dim c As Range
Dim DefaultValue As String

DefaultValue = " "

For Each c In Sheets("Comments").Range("C2:Y600")
    If Application.IsNA(c) Then
        c.Value2 = DefaultValue
    Else
        If c.Value2 = 0 Then
            c.Value2 = DefaultValue
        End If
    End If
Next

这篇关于在IF语法VBA中包含#N/A值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆