Eliminate out of memory

Forestq

Active Member
Joined
May 9, 2010
Messages
482
Hi,

let say I have code:

Code:
Dim L1 as Long, Dim L2 as Long
Dim L3 as Long, Dim L4 as Long
Dim L5 as Long, Dim L6 as Long

Dim sum_L as Long

L1 = 1
L2 = 100
L3 = 10000
L4 = 1000000
L5 = 100000000
L6 = 10000000000

sum_L = L1+L2+L3+L4+L5+L6 'error

when I try to add above value, I got error:
Run-time error '6':
Overflow

How to avoid or eleminate it?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
You may need to define all of the variables as Double (or LongLong if you have 64-bit Excel). VBA creates an internal, intermediate variable to hold each individual step of the calculation, and the size of the intermediate variable is determined by the first variable it sees.

This thread has a bit more information on the subject, although we couldn't quite find the last word from Microsoft.

https://www.mrexcel.com/forum/excel-questions/988052-dividing-1-large-ish-number-not-large.html
 
Upvote 0
thank you both!

I have used double - all variable defined as double. Works!

Thanks once again!
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,956
Members
448,535
Latest member
alrossman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top