View Single Post
  #12   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Harlan Grove[_2_] Harlan Grove[_2_] is offline
external usenet poster
 
Posts: 1,231
Default My Final #DIV/0! that I'd like to say Goodbye to!

"Dave Thomas" wrote...
I have his spreadsheet

....

That just means his sample data is all positive. Doesn't mean your formula
will always work. When you gain some experience, you'll find it's actually
easier to try to foresee potential problems. Besides, how much more
complicated would it have been to suggest

=IF(COUNT(C4:C500),AVERAGE(C4:C500),"")

As for testing AO19<0, note that if AO19 contained any text or boolean
value, this expression would return TRUE. This could be a problem if AO19
contained strings of 0 or more spaces (enter a single quote only or the
formula ="" to get a string of zero spaces - it'd be text of length zero,
which is not equal to 0). If the goal is to avoid #DIV/0! when AO19 doesn't
contain a number, then just test whether it contains a number.

=IF(COUNT(AO19),SUM(AL4:AL18)/AO19,"")
=IF(COUNT(AO19),AL4/AO19,"")

If the goal is to test whether AO19 contains something that could be treated
as a nonzero number, use

=IF(COUNT(1/AO19),SUM(AL4:AL18)/AO19,"")
=IF(COUNT(1/AO19),AL4/AO19,"")

In almost all cases, the proper way to trap reasonably anticipated #DIV/0!
errors, especially from AVERAGE, is with a COUNT call.