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

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
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,730
Messages
6,132,397
Members
449,725
Latest member
Enero1

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