检查“#N / A” vba中的值进入一个范围 [英] check a "#N/A" value in vba into a range

查看:97
本文介绍了检查“#N / A” vba中的值进入一个范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用VBA检查一个#N / A 的值。所以经过一些研究,我做了这个代码:

  Set MyTab = Range(name)
If(Not IsEmpty MyTab(i,j).value CVErr(xlErrNA))然后
调用BuildRequest(False,id,MyTab,i,j)
End If

但是当它通过 MyTab(i,j).value& CVErr(xlErrNA)我有一个错误 13(类型错误),我没有找到原因。



任何人都可以帮助我吗?

解决方案

您首先需要检查单元格是否包含错误:

  If IsError(MyTab(i,j).Value)Then 
如果MyTab(i,j).Value <> CVErr(xlErrNA)然后

除非你想知道错误的类型(#N / A, #DIV / 0 !, etc),你可以用以下替换你的测试:

  If(Not IsEmpty(MyTab.value ))And(不是IsError(MyTab(i,j).value))然后

如果你需要要检查错误类型,可以写:

  Dim shouldBuildRequest As Boolean 

shouldBuildRequest = Not IsEmpty (MyTab.value)
如果IsError(MyTab(i,j).Value)然后
shouldBuildRequest = shouldBuildRequest AND(MyTab(i,j).Value CVErr(xlErrNA))
结束如果

如果shouldBuildRequest然后
调用BuildRequest(False,id,MyTab,i,j)
End If
/ pre>

I want to check a #N/A value into excel with VBA. So after some research, I made this code :

Set MyTab = Range(name)
If (Not IsEmpty(MyTab.value)) And (MyTab(i, j).value <> CVErr(xlErrNA)) Then
   Call BuildRequest(False, id, MyTab, i, j)
End If

But when it passed on MyTab(i, j).value <> CVErr(xlErrNA) I have an error 13(type error) and I don't find why.

Anyone can help me plz ?

解决方案

You first need to check that the cell does contain an error:

If IsError(MyTab(i, j).Value) Then
    If MyTab(i, j).Value <> CVErr(xlErrNA) Then

Unless you do want to know the type of error (#N/A, #DIV/0!, etc) , you might as well replace your test with:

If (Not IsEmpty(MyTab.value)) And (Not IsError(MyTab(i, j).value)) Then

If you need to check the error type, you can write:

Dim shouldBuildRequest As Boolean

shouldBuildRequest = Not IsEmpty(MyTab.value)
If IsError(MyTab(i, j).Value) Then
    shouldBuildRequest = shouldBuildRequest AND (MyTab(i, j).Value <> CVErr(xlErrNA))
End If

If shouldBuildRequest Then
    Call BuildRequest(False, id, MyTab, i, j)
End If

这篇关于检查“#N / A” vba中的值进入一个范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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