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

AnthoHead

New Member
Joined
Jul 20, 2014
Messages
17
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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
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,224,820
Messages
6,181,154
Members
453,021
Latest member
Justyna P

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