View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.misc
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Overflow error.. why?

When doing its intermediate calculations, VBA uses the smallest data type
that it can to hold the variables. Since both 2000 and 365 can be stored in
Integers, VBA uses integers in its internal calculations. But 2000 * 365 =
730000 exceeds the maximum value of an integer, thus you get the "Overflow"
error. You can force VBA to use Longs by suffixing one of the operands with
the Long type definition character '&'. E.g.,

Dim x As Long
x = 2000& * 365


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
www.cpearson.com
(email address is on the web site)


"Fingerjob" wrote in message
...

Dim x As Long
x = 2000 * 365

Why is this statment generate a : Overflow (Error 6)
I dont understant it since x is "long" and should be able to store this
large number.

Could someone please try to explain it.

I know that the statement under will solve it.
Dim x As Long
x = CLng(2000) * 365

Best regards
Petter Bøhler