Excel macro stopping
Excel macro stopping
(OP)
Hi
I have an excel sheet that performs calculations then i use a macro to copy and paste the results into another sheet. The macro then continues to call in new data from a source and the sheet re-calculates and copy and paste again. The sheet is around 10mb in size.
I have 2 issues. Firstly the macro just stops after a period, anything from 10 mins to 10 hours. Secondly the macro takes all the CPU available on my pc. I have included a delay between calling each action 1) calling in source data 2)re-calculating sheet 3) copy and paste. But even during these gaps the macro takes all the cpu. Can i write a better macro that frees up the cpu, i am thinking maybe this 100% cpu usage is stopping the macro?
Can anyone help?
Thanks
I have an excel sheet that performs calculations then i use a macro to copy and paste the results into another sheet. The macro then continues to call in new data from a source and the sheet re-calculates and copy and paste again. The sheet is around 10mb in size.
I have 2 issues. Firstly the macro just stops after a period, anything from 10 mins to 10 hours. Secondly the macro takes all the CPU available on my pc. I have included a delay between calling each action 1) calling in source data 2)re-calculating sheet 3) copy and paste. But even during these gaps the macro takes all the cpu. Can i write a better macro that frees up the cpu, i am thinking maybe this 100% cpu usage is stopping the macro?
Can anyone help?
Thanks
RE: Excel macro stopping
I dont know about the stopping - but win 95-98 me? is not very suited for real time data acc. application as far as i know (unix or the like should be better).
Best Regards
Morten
RE: Excel macro stopping
RE: Excel macro stopping
I don't think adding a timer will help, since in VBA the timer is executed synchronously.
You could try adding a "DoEvents" statement at strategic parts of the code. This tells the program to release the CPU for other tasks, and is needed if you have "tight" CPU intensive code.
RE: Excel macro stopping
I have a word program template that reads data from an excel program (just a spreadsheet with a TON of formulas). I also have a "read me" sheet that (in effect) just reads the data from the excel program. When I try to update the wordfile without the "read me" file open, it takes forever! It takes so long because word is continually reading values, recalculating the sheet and pasting values. With the "read me" sheet open, the update takes only seconds.
I don't know what would happen if you turned excel's "Auto calculate" off and then tried your macro. It may help speed the process (it may not be an option though, from what it sounds like...). You may also want to see if you can import all the external data into an array variable in VBA or even another excel spreadsheet and try to read it from there.
Hope this helps!
jproj
RE: Excel macro stopping
For example, copying and pasting by "Range" instead of writing to cells by looping blocks, turning off screen updating by using Application.Screenupdating=False, etc.