IFERROR VB formula

Read_This

New Member
Joined
Aug 13, 2014
Messages
37
I have a worksheet of cells which have existing formulas - depending on the formula, return a 'result' or an 'error'
I would like a VB formula so I can perform a one-off solution by inserting
=IFERROR(ExistingFormula),"")
..into each selected cell formula 'the blue text'.

-------------------

For example, I have VB code to insert an absolute reference into pre-selected cells:

Sub LockCells()
'
'LockCells Macro
'
Dim c As Range
For Each c In Selection
c.Formula = Application.ConvertFormula(c.Formula, xlA1, , xlAbsolute)
Next
End Sub
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Try

Code:
Sub test()
For Each c In Selection.SpecialCells(xlCellTypeFormulas)
    c.Formula = "=IFERROR(" & Right(c.Formula, Len(c.Formula) - 1) & ","""")"
Next c
End Sub

Be careful, it will not care if the formula is 'already' using the iferror(...,"") structure.
You'd end up with =IFERROR(IFERROR(...,""),"")
 
Upvote 0
Thank you for your prompt reply, your formula worked on the whole worksheet - I hadn't pre-selected any cells, would that be correct?
 
Upvote 0
You have to pre-select the range of cells to apply the changes to.
Just like the other macro you posted.
 
Upvote 0
Thank you, when I stated "I hadn't pre-selected any cells", I had inadvertantly selected one cell however, the macro corrected the whole worksheet.

When selecting multiple cells, the macro does however, perform as requested.

Many thanks, much appreciated!
 
Upvote 0

Forum statistics

Threads
1,216,051
Messages
6,128,501
Members
449,455
Latest member
jesski

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