Results 1 to 5 of 5

Macro to add the IFERROR function to formulas

Threaded View

MadCrammer Macro to add the IFERROR... 09-25-2012, 09:57 AM
Andy Pope Re: Macro to add the IFERROR... 09-25-2012, 11:01 AM
Jacc Re: Macro to add the IFERROR... 09-25-2012, 11:16 AM
MadCrammer Re: Macro to add the IFERROR... 09-25-2012, 11:26 AM
carpy1985 Re: Macro to add the IFERROR... 01-14-2014, 12:41 PM
  1. #1
    Registered User
    Join Date
    03-17-2008
    Posts
    16

    Macro to add the IFERROR function to formulas

    I spent time scouring the interwebs trying to find a macro that would add an "IFERROR" function to any formula for the cells that are selected. I found some code and modified it to be a little more custom, so apologies in that I don't know who to give credit to.

    My issue with the below code is that if only have one cell selected, it loops through every cell in the worksheet and adds an IFERROR 'wrapper' to every formula. There seems like there should be a simple solution so that if you only have a single cell selected, the macro only applies to that cell.


    Sub wrap()
    
        'Adds =IfError() around formulas
        Dim cel As Range
        Dim rng As Range
        Dim Check As String
        Dim userInput As String
        Dim Equ As String
        
        userInput = InputBox("What would you like the cell(s) to display if there's an error?")
       
    
        Equ = "=IFERROR(_x ,""" & userInput & """)"
            
        On Error Resume Next
        Set rng = Selection.SpecialCells(xlFormulas, 23)
        If rng Is Nothing Then Exit Sub
        
        With WorksheetFunction
            For Each cel In rng
                If Not cel.Formula Like Check Then
                    cel.Formula = .Substitute(Equ, "_x", Mid$(cel.Formula, 2))
                End If
            Next
        End With
        
    End Sub
    I appreciate any feedback - thanks!!
    Last edited by MadCrammer; 09-25-2012 at 11:27 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1