+ Reply to Thread
Results 1 to 3 of 3

Automatically Changing Functions

  1. #1
    Registered User
    Join Date
    07-11-2006
    Posts
    3

    Automatically Changing Functions

    I have over 720 functions across four worksheets that commonly results in #Div/0 errors. I want to insert an "error handling" function to make those #Div/0 errors disappear. That's the easy part. I am using:

    =IF(ISERROR(OriginalFormula),"",OriginalFormula)

    --> "Original Function" could be as simple as: =((A1+A5)/(B1-B8))

    My problem is that I don't want to manually go to each cell and cut, paste, cut, paste, etc. to make the alterations to each formula.

    Is there any macro that will make each "OriginalFormula" a variable, and automatically paste the variable (original function) back into my desired new function above?

    Thanks....

  2. #2
    Ken Johnson
    Guest

    Re: Automatically Changing Functions


    bmstar wrote:
    > I have over 720 functions across four worksheets that commonly results
    > in #Div/0 errors. I want to insert an "error handling" function to
    > make those #Div/0 errors disappear. That's the easy part. I am
    > using:
    >
    > =IF(ISERROR(OriginalFormula),"",OriginalFormula)
    >
    > --> "Original Function" could be as simple as: =((A1+A5)/(B1-B8))
    >
    > My problem is that I don't want to manually go to each cell and cut,
    > paste, cut, paste, etc. to make the alterations to each formula.
    >
    > Is there any macro that will make each "OriginalFormula" a variable,
    > and automatically paste the variable (original function) back into my
    > desired new function above?
    >
    > Thanks....



    Hi bmstar,

    this worked for me...

    Public Sub ChangeToHandleError()
    Dim rngCell As Range
    Dim strFormula As String
    For Each rngCell In Application.Selection
    If Left(rngCell.Formula, 1) = "=" Then
    strFormula = Right(rngCell.Formula, Len(rngCell.Formula) - 1)
    rngCell.Formula = "=IF(ISERROR(" & strFormula & _
    "),""""," & strFormula & ")"
    End If
    Next
    End Sub

    It works on the range of cells that you select before running.

    Try it out on a copy of your sheet first.

    Ken Johnson


  3. #3
    Ken Johnson
    Guest

    Re: Automatically Changing Functions


    Hi bmstar,

    just a minor improvement so that the code doesn't change any formulas
    in the selected range that are already set up to hide the DIV0 error,
    which results in unnecessarily long formulas...

    Public Sub ChangeToHandleError()
    Dim rngCell As Range
    Dim strFormula As String
    For Each rngCell In Application.Selection
    If Left(rngCell.Formula, 1) = "=" _
    And Left(rngCell.Formula, 11) <> "=IF(ISERROR" Then
    strFormula = Right(rngCell.Formula, Len(rngCell.Formula) - 1)
    rngCell.Formula = "=IF(ISERROR(" & strFormula & _
    "),""""," & strFormula & ")"
    End If
    Next
    End Sub

    Ken Johnson


+ Reply to Thread

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