VBA Overflow error

aculham

New Member
Joined
Aug 13, 2008
Messages
6
Hello. I am having the following problem in a VBA macro i have written. I declare a bunch of variables and arrays, mostly longs and doubles, then run a DLL. After that, I redim one of my arrays (2D) to the right size and try to fill in some values. The array is a double and the values are less than one million. On the first element the code breaks and throws an overflow error. If I choose "Debug", I can then click continue and it finishes just fine as if there was no error. I can see in the debugger that the array is sized properly, has the correct type, etc. I have no idea what could be wrong here. Could it be a memory problem? Thanks in advance.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Usually for me this error has been due to mis-matching the variable type. ie. the code is expecting integer, long or double and gets something else that it cannot convert.

You might like to check that you have no Null cells in your data. This means empty cells that do not contain an explicit numeric zero. Or you might have text where the code is expecting a number. Perhaps just a space.

There are 3 basic data types possible in a cell - Text/String, Number, Null.
 
Upvote 0
Thanks for the response. I am sure that the array is defined as a double. All I do is define it, do a bunch of stuff that has nothing to do with it, then redim it to a particular size. At this point, all elements should (I think) be initialized to zero. After this I try to assign an element and it crashes. Example:

Code:
Dim myArray() As Double
 
' bunch of stuff that does nothing to myArray
 
ReDim myArray(1 to 6, 1 to 3)
 
myArray(1,1) = 1#        ' overflow

Furthermore, if I choose to debug, and it takes me to that line, then hitting continue will allow it to finish without problems. This indicates to me that there never was a problem with my assignment, but for some reason VBA throws me an error.

Anyone ever experienced such strange behavior?
 
Upvote 0
Not good Jindon - rained continuously for the first 4 days so we decided to come home early (as we were stuck in a tiny caravan with 3 screaming kids). It's a relief to be home!
 
Upvote 0
That code didn't used to error for me either. I added a few new variables recently and now it crashes every time. This is why I was thinking it may be a memory issue.

As for the 1#, it just does that when I type 1.0 so I just left it alone.
 
Upvote 0

Forum statistics

Threads
1,213,568
Messages
6,114,348
Members
448,570
Latest member
rik81h

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