How to clear memory to prevent “out of memory error” in excel vba?

后端 未结 7 2155
长发绾君心
长发绾君心 2020-11-27 18:50

I am running VBA code on a large spreadsheet. How do I clear the memory between procedures/calls to prevent an \"out of memory\" issue occurring?

Thanks

7条回答
  •  天命终不由人
    2020-11-27 19:45

    I've found a workaround. At first it seemed it would take up more time, but it actually makes everything work smoother and faster due to less swapping and more memory available. This is not a scientific approach and it needs some testing before it works.

    In the code, make Excel save the workbook every now and then. I had to loop through a sheet with 360 000 lines and it choked badly. After every 10 000 I made the code save the workbook and now it works like a charm even on a 32-bit Excel.

    If you start Task Manager at the same time you can see the memory utilization go down drastically after each save.

提交回复
热议问题