Need VBA to SLOW DOWN to prevent crashing..., Or maybe a different method?

logandiana

Board Regular
Joined
Feb 21, 2017
Messages
107
I have a macro that takes a table and loops through using autofilter to filter the table based on a list of values.
Then copies the new filtered table into its own new workbook, saves as, and closes it.
New files created are usually any where from 50 to 75 new workbooks based on the data in the table.
Here's the basic code that does this:

VBA Code:
For i = 2 To LR2

    DATA.UsedRange.AutoFilter 1, UNI.Range("A" & i).Value

    Set NBK = Workbooks.Add
    Set NST = NBK.Sheets(1)

    DATA.UsedRange.SpecialCells(xlCellTypeVisible).Copy NST.Range("A1")

    NBK.SaveAs ARM.Path & "\" & who & "\SPLIT FILES\" & UNI.Range("A" & i).Value & ".xlsx"

    NBK.Close True

    DATA.UsedRange.AutoFilter

Next i

This has worked just fine for me and for many others that the program was built for.
There are a few however, where about halfway through, excel just completely crashes and closes without warning.
On the computers with this issue, when the code is running, the CPU is pegged out at 100% before the application crashes.
taskmgr.jpg


On my computer and others that work, the CPU% will get up to the high 90s and sometimes touch 100%, but it never just stays there causing the app to crash.
For the computers that have the apps that crash, I have made sure that they don't have other stuff running that would interfere, and made sure that they didn't have other 3rd party excel add ins enabled.
This hasn't seemed to make a difference, so rather than chalk it up to 'they just need a faster computer' to make this code work, I wonder if there is a way to slow down the macro.
Is there something I can put in the code to make it complete the same process automatically, but just take a little longer so the processor isn't taxed as much?
Or is there some alternative code that I should be using that would achieve the same goal without the burden on the processor?
Thanks
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,224,745
Messages
6,180,699
Members
452,994
Latest member
Janick

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