Overflow in VBA, but value < limit

B

Brad

Okay, I¹ve declared a value ³total² as Long ...

The following causes an overflow ... Of the long integer ³total²

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.)
 
C

Colo

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:
 
D

Dana DeLouis

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top