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

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

    If you operate on a large dataset, it is very possible that arrays will be used. For me creating a few arrays from 500 000 rows and 30 columns worksheet caused this error. I solved it simply by using the line below to get rid of array which is no longer necessary to me, before creating another one:

    Erase vArray
    

    Also if only 2 columns out of 30 are used, it is a good idea to create two 1-column arrays instead of one with 30 columns. It doesn't affect speed, but there will be a difference in memory usage.

    0 讨论(0)
提交回复
热议问题