Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 690
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Overflow in VBA, but value < limit

Dana, thanks for your input. :D


---
Message posted from http://www.ExcelForum.com/

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
What is format overflow? Chantele New Users to Excel 2 March 4th 09 04:51 PM
Overflow error.. why? Fingerjob Excel Discussion (Misc queries) 4 November 13th 06 05:18 PM
Overflow Error DG Excel Discussion (Misc queries) 3 April 15th 05 05:45 PM
VBA overflow Tom Ogilvy Excel Programming 3 September 2nd 03 09:04 PM
VBA overflow Don Guillett[_4_] Excel Programming 2 September 2nd 03 04:19 PM


All times are GMT +1. The time now is 10:19 AM.

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"