LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 7,247
Default Overflow error.. why?

Yes, 2000& is better than CLng(2000) for the reason you suspect. 2000& is
made a Long at compile time, and CLng is a function call done at run time.


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

wrote in message
oups.com...
Chip: Is 2000& better than CLng (2000)? Is the former done at compile
time, and therefore not calling to a function?

Dom


Chip Pearson wrote:
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





 
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
Data overflow to second worksheet jv Excel Worksheet Functions 0 March 30th 06 06:06 PM
allow text to overflow into the next cell? gbwoodman Excel Discussion (Misc queries) 1 February 7th 06 12:42 PM
Text Cell Overflow tonymaguire Excel Discussion (Misc queries) 4 October 6th 05 08:32 AM
runtime error '6' overflow don Setting up and Configuration of Excel 1 July 26th 05 02:52 AM
Overflow Error DG Excel Discussion (Misc queries) 3 April 15th 05 05:45 PM


All times are GMT +1. The time now is 02:43 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"