ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Macro erro (https://www.excelbanter.com/excel-discussion-misc-queries/169863-macro-erro.html)

orquidea

Macro erro
 
Hi

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.

Could anyone help me to solve this problem?

Thanks,
Orquidea

FSt1

Macro erro
 
hi
you could wrap it in an if statement to test for zero.
if our20/total20< 0 then
per=(our20/total20)
end if
or....
if our20/total20= 0 then
do something else
else
per=(our20/total20)
end if

my thoughts
Regards
FSt1
"orquidea" wrote:

Hi

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.

Could anyone help me to solve this problem?

Thanks,
Orquidea


orquidea

Macro erro
 
Thanks a lot for your help. It worked.

Orquidea
"FSt1" wrote:

hi
you could wrap it in an if statement to test for zero.
if our20/total20< 0 then
per=(our20/total20)
end if
or....
if our20/total20= 0 then
do something else
else
per=(our20/total20)
end if

my thoughts
Regards
FSt1
"orquidea" wrote:

Hi

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.

Could anyone help me to solve this problem?

Thanks,
Orquidea


FSt1

Macro erro
 
glad to help

regards
FSt1

"orquidea" wrote:

Thanks a lot for your help. It worked.

Orquidea
"FSt1" wrote:

hi
you could wrap it in an if statement to test for zero.
if our20/total20< 0 then
per=(our20/total20)
end if
or....
if our20/total20= 0 then
do something else
else
per=(our20/total20)
end if

my thoughts
Regards
FSt1
"orquidea" wrote:

Hi

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.

Could anyone help me to solve this problem?

Thanks,
Orquidea


Rick Rothstein \(MVP - VB\)

Macro erro
 
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


Rick Rothstein \(MVP - VB\)

Macro erro
 
It worked??? Are you sure?

Testing our20/total20 in an If statement will generate an error if total20
is equal to 0.

Rick


"orquidea" wrote in message
...
Thanks a lot for your help. It worked.

Orquidea
"FSt1" wrote:

hi
you could wrap it in an if statement to test for zero.
if our20/total20< 0 then
per=(our20/total20)
end if
or....
if our20/total20= 0 then
do something else
else
per=(our20/total20)
end if

my thoughts
Regards
FSt1
"orquidea" wrote:

Hi

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.

Could anyone help me to solve this problem?

Thanks,
Orquidea



orquidea

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



FSt1

Macro erro
 
yes.
I answered to quick on this one. what popped in my mind was "test for zero"
and i didn't think about what i wrote enought. I would have caught if i have
tested but i didn't test which i usually do.
sorry for the miss lead.
regards
FSt1

"orquidea" wrote:

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




All times are GMT +1. The time now is 01:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com