Run Time Error from: HHH = 24 * 3600

User Name

Spammer
Joined
Aug 10, 2010
Messages
182
I'm getting a run time error from HHH = 24 * 3600.

HHH is a double. What on earth could be causing an overflow error here?

The exact message is runtime error '6': Overflow
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
It has something to do with floating point precision.
I don't fully understand this issue, but it's well documented at Microsoft's website
Search for floating point precision


As an alternative, this works

Dim x As Double, y As Double, z As Double
x = 24
y = 3600
z = x * y

Again, don't understand why, but I know it's related to floating point precision.
 
Last edited:
Upvote 0
from VB help:

Overflow (Error 6)


An overflow results when you try to make an assignment that exceeds the limitations of the target of the assignment. This error has the following causes and solutions:

The result of an assignment, calculation, or data type conversion is too large to be represented within the range of values allowed for that type of variable.
Assign the value to a variable of a type that can hold a larger range of values.

An assignment to a property exceeds the maximum value the property can accept.
Make sure your assignment fits the range for the property to which it is made.

You attempt to use a number in a calculation, and that number is coerced into an integer, but the result is larger than an integer. For example:
Dim x As Long
x = 2000 * 365 ' Error: Overflow
To work around this situation, type the number, like this:

Dim x As Long
x = CLng(2000) * 365


try the clng() option - works for me
 
Upvote 0
Ahh, it's not the floating point..

The calculation 24*3600 happens before assigning it to the variable...
And when calculating hard coded numbers, it considers them Integers, and the result of the calculation is larger than an integer.

Interesting...
 
Upvote 0
Hmmm... OK... when I set 24 and 3600 equal to ARG1 and ARG2 the math goes through. Very very strange.

Thanks for the help. Problem kinda sorta solved. :)
 
Upvote 0
Hmmm... OK... when I set 24 and 3600 equal to ARG1 and ARG2 the math goes through. Very very strange.

Thanks for the help. Problem kinda sorta solved. :)

Consider pcc's response...

By assigning 24 and 3600 to ARG1 and ARG2, presumeably you DIMMED them as Double.

This forced VBA to use the Double Data type

Doing it the original way, hard coding the #s in the multiplication, VBA used the Integer Data Type, because both values (prior to the math) were less than the Integer maximum value.
 
Upvote 0
OK... pcc's CLng method works and it's cleaner so I'll go with it. Thanks to both of you for the help. The info is going in the vault.
 
Upvote 0

Forum statistics

Threads
1,224,563
Messages
6,179,527
Members
452,923
Latest member
JackiG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top