check a “#N/A” value in vba into a range

后端 未结 2 392
礼貌的吻别
礼貌的吻别 2021-01-18 19:10

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         


        
相关标签:
2条回答
  • 2021-01-18 19:38

    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
    
    0 讨论(0)
  • 2021-01-18 19:47

    Another way to check for the error

    If CVErr(MyTab(i, j).Value) = CVErr(xlErrNA)
    
    0 讨论(0)
提交回复
热议问题