IfError VBA Returning 0 as text and I need it as a number

AnthoHead

New Member
Joined
Jul 20, 2014
Messages
15
I have been at this for over an hour now and can't seem to find an answer or figure it out.

I have this IfError VBA code I've been using that will return a 0 for me.


Sub WrapFormulasWIthIFERROR_0()
Dim Cell As Range
For Each Cell In Selection
If Cell.HasFormula Then
If Left(Cell.Formula, 9) <> "=IFERROR(" Then
Cell.Formula = "=IFERROR(" & Mid(Cell.Formula, 2) & ",""0"")"
End If
End If
Next
End Sub

However, the "0" it returns is in text format and not number format. I need it to be in number format as there are some additional formulas I'm using that require it to be a number. Does anyone know the quick fix for this? Sorry, I'm still learning here and I'm sure this is something super easy.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
I have been at this for over an hour now and can't seem to find an answer or figure it out.

I have this IfError VBA code I've been using that will return a 0 for me.


Sub WrapFormulasWIthIFERROR_0()
Dim Cell As Range
For Each Cell In Selection
If Cell.HasFormula Then
If Left(Cell.Formula, 9) <> "=IFERROR(" Then
Cell.Formula = "=IFERROR(" & Mid(Cell.Formula, 2) & ",""0"")"
End If
End If
Next
End Sub

However, the "0" it returns is in text format and not number format. I need it to be in number format as there are some additional formulas I'm using that require it to be a number. Does anyone know the quick fix for this? Sorry, I'm still learning here and I'm sure this is something super easy.
Maybe remove the double quotes, that I believe would make it a value.
 
Upvote 0
Your code would look like this

VBA Code:
Sub WrapFormulasWIthIFERROR_0()
    Dim Cell As Range
    For Each Cell In Selection
        If Cell.HasFormula Then
            If Left(Cell.Formula, 9) <> "=IFERROR(" Then
                Cell.Formula = "=IFERROR(" & Mid(Cell.Formula, 2) & ",0)"
            End If
        End If
    Next
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,216,761
Messages
6,132,570
Members
449,736
Latest member
anthx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top