Insufficient memory when closing unnecessary workbook!?

vschoet

New Member
Joined
Mar 17, 2017
Messages
5
Hey guys,



I'm getting an inexplicable memory error while trying to optimize my code.


My macro is pretty big and totally not optimized, but it shouldn't be exceeding the limits of this computer quite yet.
Even stranger so: the error only occurs when trying to close an unnecessary workbook, in an effort to clear memory!


The involved secondary workbook is used just to extract some array's of data.
In it, there are 4 variable ranges of data that I need to work with, like this:


Set xxwrng = variablerange1 in secondary workbook
Set xxxrng = variablerange2 in secondary workbook
Set xxyrng = variablerange3 in secondary workbook
Set xxzrng = variablerange4 in secondary workbook


After that I compare values in my main workbook against these ranges.
Then the secondary workbook has no more use.


Originally I close this workbook at the very end of my macro. => no memory issues!
But now I tried to optimize my code, by closing this unnecessary workbook right after the comparison.
This is when I get the insufficient memory error!


I tried: Erasing the arrays, setting their values to nothing etc etc.


Can anyone explain this one?


Any referral to a beginner VBA memory management resource would also be greatly appreciated.

Atm I just write line after line of code, without organizing it in any optimized way.

Thank you in advance!
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Yongle

Well-known Member
Joined
Mar 11, 2015
Messages
5,636
Office Version
365
Platform
Windows
Try setting all 4 ranges to nothing before closing the workbook.
Code:
Set xxxrng = Nothing
Determining the cause of your memory error :confused: would be easier if you posted your complete code :)
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,095,480
Messages
5,444,733
Members
405,298
Latest member
fxtrtr17

This Week's Hot Topics

Top