Excel crashing due to loop

MarkCBB

Active Member
Joined
Apr 12, 2010
Messages
497
HI there,

I am running some code that very basically copies and moves a sheet from a workbook and saves it, every loop creates an invoice, currently it loops 170 times but excel cant seem to make it past 170 all the time. is there any reason why this happens?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
There's nowt inherently significant about that number like there is about 255, 32767, 1048576, etc.

I'm assuming you don't have an On Error directive active in your code at the point at which the loop terminates.

Have you tried stepping through your code to find out what's triggering the condition which causes your loop to terminate?
 
Upvote 0
What happens if you start your loop at, say, the 150th invoice? Does it still stop after 170 invoices, or does it stop after 20?
 
Upvote 0
Rather than moving the sheet, you could try:

add a new workbook
activate the source workbook
copy the cells (or just the used range)
activate the new workbook
paste the data (or paste values, format, whatever you want
(clear the clipborad afterwards)
rename the sheet if necessary
delete sheet from source workbook

I have had similar probelms in the past and this worked for me

The end result is the same
Cheers
 
Upvote 0
HI there Guys,

I have step though it (takes along time to do) when I step though it it seems to work. however when i run the code it sometimes works and sometimes "excel is not responding, once that happens the dugbug box appears, however there is not bug. the code is very simple.

the strange thing is that sometimes it will run for all 170, and somtimes it doesnt, maybe excel is casheing the copied worksheets?
 
Upvote 0
This might be a weird suggestion but you could try saving the file after every 100 processed invoices (possibly to a temporary location). This could clear Excel's cache, or at least parts of it.
 
Upvote 0
Did you try my suggestion?
 
Upvote 0
@pcc, hey that sounds like an idea, how would i clear the clipboard?

@Moonfish, I cant save after 100 as they are all individual invoices for separate companies.
 
Upvote 0
Application.CutCopyMode = False
 
Upvote 0

Forum statistics

Threads
1,224,522
Messages
6,179,299
Members
452,904
Latest member
CodeMasterX

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top