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

后端 未结 7 2143
长发绾君心
长发绾君心 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:44

    Found this thread looking for a solution to my problem. Mine required a different solution that I figured out that might be of use to others. My macro was deleting rows, shifting up, and copying rows to another worksheet. Memory usage was exploding to several gigs and causing "out of memory" after processing around only 4000 records. What solved it for me?

    application.screenupdating = false

    Added that at the beginning of my code (be sure to make it true again, at the end) I knew that would make it run faster, which it did.. but had no idea about the memory thing.

    After making this small change the memory usage didn't exceed 135 mb. Why did that work? No idea really. But it's worth a shot and might apply to you.

提交回复
热议问题