ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How can I rewrite IF IsError Function to Work in VBA (https://www.excelbanter.com/excel-programming/436750-how-can-i-rewrite-if-iserror-function-work-vba.html)

DogLover

How can I rewrite IF IsError Function to Work in VBA
 
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)

JoeU2004

How can I rewrite IF IsError Function to Work in VBA
 
"DogLover" wrote:
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)





All times are GMT +1. The time now is 02:26 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com