Thread: Macro erro
View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.misc
orquidea orquidea is offline
external usenet poster
 
Posts: 132
Default Macro erro

Here is how I rewrote the procedure based on FSt1's answer.
If Total20 < 0 Then
per = (our20 / total20)
End If
I tested this and worked. I know when divisions are done in spreadsheet
where a number is divided by Zero, the message "#DIV/0!" pops up. Therefore
I assumed that the error I got with FSt1's answer was because of that.
That's why I rewrote the procedure above.

Thanks for your explanation. It helps me to understand better how macros
should be set.

Orquidea


"Rick Rothstein (MVP - VB)" wrote:

I have the following subprocedure
Per=(our20/total20)
Some times the variables our20 and total20 will be =0. In these
situations,
I am getting the message "Run-time error'6' overflow" . The
subprocedure
above is highlighted. I believe it is because the division is 0/0.


Zero divided by any number (except zero) equals zero, so the numerator being
zero is not the problem. On the other hand, any number divided by zero is
(in imprecise mathematical terms) infinity, which is not a number; so, VB
returns an error for division by zero. The special case of zero divided by
zero is undefined, not infinity... the reason (again, in imprecise
mathematical terms) has to do with the previous two statements... any number
divided by zero is infinity but zero divided by any number is zero... there
is no way to decide which of these holds for a result, zero or infinity, so
the division of zero by zero is undefined.

Anyway, the way to handle your problem is to test the denominator for
zero...

If total20 = 0 Then
'
' Handle your error here. There are lots of ways to do this, but they
' all depend on how you want your program to proceed for this case
'
Else
Per = our20 / total 20
End If

Rick