#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default 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

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 132
Default 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

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,202
Default 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



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 2,202
Default 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


  #7   Report Post  
Posted to microsoft.public.excel.misc
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


  #8   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,942
Default 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


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to add erro bars for each bar, rather than the whle series Lumos Charts and Charting in Excel 1 September 18th 07 03:46 AM
Macro Help Needed - Excel 2007 - Print Macro with Auto Sort Gavin Excel Worksheet Functions 0 May 17th 07 01:20 PM
Excel Erro Mindie Setting up and Configuration of Excel 1 May 29th 06 02:08 AM
Erro in Formula, Pleas Help? jsc3489 Excel Worksheet Functions 3 July 25th 05 04:39 PM
Macro needed to Paste Values and prevent Macro operation thunderfoot Excel Discussion (Misc queries) 0 June 10th 05 03:38 PM


All times are GMT +1. The time now is 08:25 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"