+ Reply to Thread
Results 1 to 5 of 5

Using Iferror formula along with if else

  1. #1
    Registered User
    Join Date
    07-23-2017
    Location
    Peoria, USA
    MS-Off Ver
    2016
    Posts
    55

    Using Iferror formula along with if else

    Hello Dear ones,

    I have an nested if else formula that I need to write in VBA, The formula has additional Iferror on it -

    =IFERROR(IF(M4<=AA4,M4/AA4,(IF(M4<=SUM(AA4:AB4),($C$2+((M4-AA4)/AB4)),((1+$C$2)+(M4-SUM(AA4:AB4))/AC4)))),999)

    This is what I have tried

    For i = 4 To lrow
    If Range("M" & i).Value <= Range("AA" & i).Value Then
    Range("V" & i).Value = Range("M" & i).Value / Range("AA" & i).Value
    ElseIf Range("M" & i).Value <= WorksheetFunction.Sum(Range("AA" & i), Range("AB" & i)) Then
    Range("V" & i).Value = Range("C2").Value + ((Range("M" & i).Value - Range("AA" & i).Value) / Range("AB" & i).Value)
    Else
    Range("V" & i).Value = (1 + Range("C2").Value) + (Range("M" & i).Value - WorksheetFunction.Sum(Range("AA" & i), Range("AB" & i)) / Range("AC" & i).Value)
    End If
    Next i

    I am not sure how to accommodate the iferror in this code.

    Thank you for helping

    Prasenjit

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Using Iferror formula along with if else

    Why do you need to "write it in VBA"? You could just use VBA to drop the existing formula into the entire range and then convert to values.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Using Iferror formula along with if else

    Administrative Note:

    Welcome to the forum.

    We would very much like to help you with your query, however you need to include code tags around your code.

    Please take a moment to add the tags. Posting code between tags makes your code much easier to read and copy for testing, and it also maintains VBA formatting.

    Please see Forum Rule #2 about code tags and adjust accordingly. Click on Edit to open your post, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (Note: this change is not optional.)


    You could use:

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-23-2017
    Location
    Peoria, USA
    MS-Off Ver
    2016
    Posts
    55

    Re: Using Iferror formula along with if else

    Thanks. Now I understand What you meant!

  5. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,428

    Re: Using Iferror formula along with if else

    You're welcome.


    If you really do want to work it out long hand manually, you just need to consider what might cause an error. In this case, it would be a Divide By Zero. So, you could check Range("AA" & i).Value, Range("AB" & i).Value, and Range("AC" & i).Value for zero before you do anything else.

    But, in my opinion, it is much harder to read than the formula, much more prone to error, and probably less efficient.


    Please don't forget the Code Tags.




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. IFERROR Formula
    By younan in forum Excel General
    Replies: 8
    Last Post: 05-06-2019, 12:51 PM
  2. [SOLVED] If/Then Formula of IFERROR
    By sclinger13 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-13-2017, 03:31 AM
  3. [SOLVED] Multiple IFERROR or IFERROR w/ If Statements
    By SanchoPanza1 in forum Excel General
    Replies: 4
    Last Post: 03-31-2016, 08:09 PM
  4. [SOLVED] IFERROR(MATCH & IFERROR(SMALL Help Needed
    By chad328 in forum Excel Formulas & Functions
    Replies: 14
    Last Post: 01-17-2016, 06:34 AM
  5. Iferror or other formula
    By sarahqputra in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 02-11-2015, 07:31 AM
  6. xlfn.IFERROR or IFERROR don't work in Excel 98-2003
    By dj_danu01 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-26-2013, 02:53 AM
  7. [SOLVED] #DIV/0 IFERROR formula
    By rlkerr in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-03-2012, 10:33 AM

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