Checking for #N/A in Excel cell from VBA code

后端 未结 1 1743
礼貌的吻别
礼貌的吻别 2020-11-27 20:19

I\'m iterating through a range of cells which hold numbers with 2 decimal places. I need to check if the cell holds \'#N/A\', and if it does, I need to skip it. The problem

相关标签:
1条回答
  • 2020-11-27 20:53

    First check for an error (N/A value) and then try the comparisation against cvErr(). You are comparing two different things, a value and an error. This may work, but not always. Simply casting the expression to an error may result in similar problems because it is not a real error only the value of an error which depends on the expression.

    If IsError(ActiveWorkbook.Sheets("Publish").Range("G4").offset(offsetCount, 0).Value) Then
      If (ActiveWorkbook.Sheets("Publish").Range("G4").offset(offsetCount, 0).Value <> CVErr(xlErrNA)) Then
        'do something
      End If
    End If
    
    0 讨论(0)
提交回复
热议问题