How can I rewrite IF IsError Function to Work in VBA

  • Thread starter Thread starter DogLover
  • Start date Start date
D

DogLover

I am trying to write this code in VBA. Does anyone know the best code to
make this work?

If (IsError(mSumIfs / Kountifs),"NA", mSumIfs / Kountifs)
 
DogLover said:
I am trying to write this code in VBA. Does anyone know
the best code to make this work?
If (IsError(mSumIfs / Kountifs),"NA", mSumIfs / Kountifs)

One way:

Dim z as Variant
On Error Resume Next
z = mSumIfs / Kountifs
If Err <> 0 Then z = "NA"
On Error GoTo 0

If you meant the Excel error #NA instead of the string "NA", then:

If Err <> 0 Then z = CVErr(xlErrNA)
 
Back
Top