Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Overflow in VBA, but value < limit
Okay, Iıve declared a value ³total² as Long ...
The following causes an overflow ... Of the long integer ³total² total = 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 But Total = 2 ^ 16 Does not ... Is there a limit to the number of multiply signs I can include in a line?? Obviously, Iım not doing this actual sum in my macro multiplies together a number of variables (a, b, c, e ... Etc) How can I overcome this limitation? Cheers, Brad.) |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Overflow in VBA, but value < limit
Hi Brad,
The NUMBER 2 is considered to be an INTEGER type in Excel. See Debug.Print TypeName(2). It returns "Integer". A variable "total" has been declared as long but Excel need to calculate before input value to "total". It return a message "Overflow" when the value is over 32,767.(The limit of Integer type) So change the code something like below .. Code: -------------------- total = 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& -------------------- Or Code: -------------------- total = CLng(2) * CLng(2) * CLng(2) * CLng(2) * CLng(2) * _ CLng(2) * CLng(2) * CLng(2) * CLng(2) * CLng(2) * _ CLng(2) * CLng(2) * CLng(2) * CLng(2) * CLng(2) * CLng(2) -------------------- --- Message posted from http://www.ExcelForum.com/ |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Overflow in VBA, but value < limit
Just to add. If Excel sees that just one of the values is long, it will use
that. Here, only the first 2 is "2&." Sub Demo() Dim Total As Long Total = 2& * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 End Sub -- Dana DeLouis = = = = = = = = = = = = = = = = = "Colo" wrote in message ... Hi Brad, The NUMBER 2 is considered to be an INTEGER type in Excel. See Debug.Print TypeName(2). It returns "Integer". A variable "total" has been declared as long but Excel need to calculate before input value to "total". It return a message "Overflow" when the value is over 32,767.(The limit of Integer type) So change the code something like below .. Code: -------------------- total = 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& * 2& -------------------- Or Code: -------------------- total = CLng(2) * CLng(2) * CLng(2) * CLng(2) * CLng(2) * _ CLng(2) * CLng(2) * CLng(2) * CLng(2) * CLng(2) * _ CLng(2) * CLng(2) * CLng(2) * CLng(2) * CLng(2) * CLng(2) -------------------- |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Overflow in VBA, but value < limit
|
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
What is format overflow? | New Users to Excel | |||
Overflow error.. why? | Excel Discussion (Misc queries) | |||
Overflow Error | Excel Discussion (Misc queries) | |||
VBA overflow | Excel Programming | |||
VBA overflow | Excel Programming |