Help with VBA macro causing excel to crash?

BobMillar

New Member
Joined
Jan 5, 2017
Messages
6
I have a very simple macro that carries out a simple repetitive task involving copying the highlighted cells (mostly formulae) and pasting back above the highlighted (Effectively the Copy & Insert Copied cells commands). Here's the VBA:

Sub CopyInsert()
' Macro to copy and insert a line or range
Selection.Copy
Selection.Insert Shift:=xlDown
End Sub

Here's the error:

"Run-Time error '-2147417848 (80010108)':
Automation Error
The object invoked has disconnected from its clients." I've tried Debug and it doesn't help - only solution is to kill excel and restart.

I use this macro in a dozen or more spreadsheets on a regular basis and on most it works fine but on some it causes excel to crash (the files are in two types with slight formula differences as to whether it is looking at gas or electricity prices stored in a single external spreadsheet - it's always the gas ones that fail for no obvious reason). In the files where it crashes it seems to cause it only on certain sheets and always on the same ones - so it will work fine on one sheet then moving to another which performs calculations on data in the first and it crashes. When I run the macros in the same file on a colleagues machine (a desktop) it's fine.... So I thought this might be a hardware / memory issue - I've just changed laptops and upgraded the newer laptop from 4GB RAM to 8GB RAM but no improvement. While writing this I've found that in a file it previously errored it didn't when I just tried it so it is clearly an intermittent problem and may be related to what else happens to be running on the machine at the time. The spreadsheet I'm running the macro on isn't small (around 10MB) as is the file containing the raw data. It doesn't seem to matter whether I have the raw data file open or not except that the links are updated quicker when it's open obviously.

Any suggestions on what might be causing this or how to diagnose the problem? Any suggestions on how I might modify the macro to prevent the error (I've already tried keeping automatic recalculate off and calculating in various stages of the macro - no difference).

Thanks!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
I select a row for example, run the macro which copies the row and inserts a copy if it just above the selected row. all it does is save 2-3 mouse clicks, but I tend to do it 7 times in quick succession - to update my table once a week.
 
Upvote 0

Forum statistics

Threads
1,215,220
Messages
6,123,697
Members
449,117
Latest member
Aaagu

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