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?
 

Eric W

MrExcel MVP
Joined
Aug 18, 2015
Messages
8,994
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
 

Forestq

Active Member
Joined
May 9, 2010
Messages
482
thank you both!

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

Thanks once again!
 

Forum statistics

Threads
1,082,259
Messages
5,364,099
Members
400,779
Latest member
lumers

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top