+ Reply to Thread
Results 1 to 7 of 7

Altering formula for errors

  1. #1
    Registered User
    Join Date
    01-05-2010
    Location
    UK
    MS-Off Ver
    Excel 2002
    Posts
    6

    Question Altering formula for errors

    Hi

    I'm trying to create a macro to alter a range of cells so that they are encased in an =IF(ISERROR(x),0,x) structure (where x is the formula that was previously in the cell). My attempt so far is:-

    Please Login or Register  to view this content.
    This isn't working so far - any tips on how I can change this? I'm also not sure that this would work if I selected a range of cells - could you help me add this please?

    Thanks
    Paul

  2. #2
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Altering formula for errors

    Welcome to the Board.

    There will be a few approaches, one (based on updating all formulae within selection at run time) might be:

    Please Login or Register  to view this content.
    your earlier code would work were you to correct the parentheses in the final formula, ie:

    =IF(ISERROR(formula),0,formula)

    rather than

    =IF(ISERROR(formula,0,formula))

  3. #3
    Registered User
    Join Date
    01-05-2010
    Location
    UK
    MS-Off Ver
    Excel 2002
    Posts
    6

    Smile Re: Altering formula for errors

    Brilliant - thanks for that.

    I just ran your code with one cell selected and my entire worksheet has had all of its formulas changed! Is there a way of tweaking the code so that it only runs on the selected cell(s)?

    Thanks again - really appreciate the help

    Paul

  4. #4
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Altering formula for errors

    Alternative (avoiding SpecialCells)

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-05-2010
    Location
    UK
    MS-Off Ver
    Excel 2002
    Posts
    6

    Re: Altering formula for errors

    Perfect - works like a charm.

    My next task is to create a macro that does the inverse and strips out the If(is(error()) code. My first idea was to use a FIND function to locate the sequence of
    Please Login or Register  to view this content.
    characters half way through the function, and then use some of the text manipulation functions (RIGHT?) to trim the rest of the formula off. However, I worry that this might catch a formula that happens to have this string of characters in it.

    Is there a more elegant way of doing this?

    Thanks again - you've been really helpful.

    Paul

  6. #6
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Altering formula for errors

    Perhaps along the lines of:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-05-2010
    Location
    UK
    MS-Off Ver
    Excel 2002
    Posts
    6

    Re: Altering formula for errors

    Wonderful! Elegant and efficient, it most certainly is. Thanks a bunch

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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