Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

check a "#N/A" value in vba into a range

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 ?

like image 787
Adrien A. Avatar asked Jul 09 '12 11:07

Adrien A.


People also ask

What's better TrustATrader or Checkatrade?

TrustATrader. TrustATrader is a site that was set up to compete directly with Checkatrade. While they have less advertising, they have a better reputation with Trustpilot. So you might get fewer leads, but the leads you get should be more solid.

Is Checkatrade any good?

Yes, it's absolutely worth joining Check A Trade even if you have much work on. This is because the site does more than just find tradespeople work. It helps to establish them as trustworthy professionals, and essentially works as a form of online word of mouth.

How do I find reliable local tradesmen?

Check with your local council Trading Standards is a council department that makes sure companies don't break the law when selling to customers. The council might list traders they've approved, or they might link to another website that lists traders in your area you can trust.


1 Answers

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
like image 162
assylias Avatar answered Oct 03 '22 00:10

assylias