+ Reply to Thread
Results 1 to 6 of 6

Divide by zero error

  1. #1
    Registered User
    Join Date
    05-19-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 365
    Posts
    40

    Divide by zero error

    Hi,

    I am using Excel 2010. I have an array that calculates an average based on certain criteria. Everything works fine except I get #DIV/0! if there is no data.

    My array is:

    {=AVERAGE(IF(ALL!B:B=B1,
    IF(ALL!D:D=B4,
    IF(ALL!E:E=C4,
    IF(DATE(YEAR(ALL!F:F),MONTH(ALL!F:F),1)=D3,
    ALL!H:H)))))}

    Please see attached example. There are 2 tabs. The raw data is on the ALL tab. The array formulas with the errors are on the "Compliance" tab, row 4. (I have only filled in row 4 so far, but eventually I will populate the other 7 rows with formulas).

    Help!
    Also, I noticed the spreadsheet has gotten very slow. I suppose this is due to the array, but is there any way to fix that?

    Thanks!
    Attached Files Attached Files

  2. #2
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Divide by zero error

    Don't use entire columns as range references in array formulas. Use smaller specific ranges.

    Array entered**:

    =IFERROR(AVERAGE(IF(ALL!B3:B20=B1,IF(ALL!D3:D20=B4,IF(ALL!E3:E20=C4,IF(ALL!F3:F20-DAY(ALL!F3:F20)+1=D3,ALL!H3:H20))))),"")

    ** array formulas need to be entered using the key
    combination of CTRL,SHIFT,ENTER (not just ENTER).
    Hold down both the CTRL key and the SHIFT key
    then hit ENTER.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  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
    48,357

    Re: Divide by zero error

    You're using 2010 so add an IFERROR, thus:

    {=IFERROR(AVERAGE(IF(ALL!B:B=B1,
    IF(ALL!D:D=B4,
    IF(ALL!E:E=C4,
    IF(DATE(YEAR(ALL!F:F),MONTH(ALL!F:F),1)=D3,
    ALL!H:H))))),0)}


    I would not recommend using full column ranges for your calculations. They are noticeably slow as each range has over a million cells.


    Regards, TMS
    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


  4. #4
    Registered User
    Join Date
    05-19-2009
    Location
    Washington, DC
    MS-Off Ver
    Excel 365
    Posts
    40

    Re: Divide by zero error

    Tony Valko and TMShucks:

    Thanks to both of you. I took your advice and reduced the range reference and I used the IFERROR and everything works great!

    Thanks thanks thanks thanks!!!

  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
    48,357

    Re: Divide by zero error

    You're welcome. Thanks for the rep.



    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.

  6. #6
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Divide by zero error

    You're welcome. Thanks for the feedback!

+ 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