Replace error with value

MrThor

New Member
Joined
Aug 13, 2018
Messages
36
Hi, I have a excel sheet with several columns with formulas in the cells. In some of the cells the message "#SAKNAS!" appears, I want to replace the value with "0". I tried the following code but it does not work.

Code:
    Cells.Replace What:="#SAKNAS!", Replacement:="0", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Why not just wrap the formula in Iferror
=IFERROR(your formula,0)
 
Upvote 0
This will replace all formula that result in an error with 0
Code:
Sub MrThor()
   Cells.SpecialCells(xlFormulas, xlErrors).Value = 0
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,996
Messages
6,175,858
Members
452,676
Latest member
woodyp

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