GETPIVOTDATA error example

Wrap If Error Macro

So as promised, here’s the code to wrap formulae in an IFERROR statement once you’re happy that the original formula is as you want it. This should prevent the need to constantly rewrite your formulae inside the iferror, or the manual need to wrap iferror around it after the fact.

Sub WrapIfError()
Dim c As Range
For Each c In Selection.Cells
If c.HasFormula And Not c.HasArray Then
c.Formula = "=IFERROR(" & Right(c.Formula, Len(c.Formula) - 1) & ",0)"
End If
End Sub

Paste this code into a relevant module, and when you’re ready, select the formulae you want to wrap, then call this code. I have this as an icon in the Quick Access Toolbar, so it’s always on hand.

If modules, the Quick Access Toolbar, or macros, are all terms which baffle rather than enlighten, don’t worry. We’ll be covering them all in due course. I just wanted to get this post live asap as there’s a link to it in the original iferror post.

Thanks for reading, and don’t forget to rate this post or send me cash. Preferably large denominations of unused… ;-)


No ratings yet.

Please rate this

0 comments on “Wrap If Error MacroAdd yours →

Leave a Reply

Your email address will not be published. Required fields are marked *