Macro error Method 'Insert' of object "Range' failed

Status
Not open for further replies.

AGibson73

New Member
Joined
Aug 2, 2020
Messages
5
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

My macro uses the following code, but as it turns out for some reason I get (random) error messages. I can't determine the action that causes this so any thoughts would be appreciated.

This macro is triggered by clicking the copy image.

1600651131630.png


The macro then determines the row that the image is linked to, inserts a row below it, and copies the contents down.

1600651147405.png


The code is as follows.

Sub AddRow()
With ActiveSheet
.Unprotect
With Intersect(.Shapes(Application.Caller).TopLeftCell.EntireRow, .UsedRange)
.Copy
.Offset(1).Insert Shift:=xlDown
End With
Application.CutCopyMode = False
.protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End With

End Sub

ERROR MESSAGE that I receive from time to time...
Run-time error '-21474178-48 (80010108)':
Method 'Insert' of object "Range' failed

Not sure if this is relevant but the code to delete a row is as follows. This is triggered by clicking the trash can image:

Sub DeleteRow()
With ActiveSheet
.Unprotect
.Shapes(Application.Caller).TopLeftCell.EntireRow.Delete
.protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End With

End Sub
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Status
Not open for further replies.

Watch MrExcel Video

Forum statistics

Threads
1,129,568
Messages
5,637,097
Members
416,957
Latest member
Brovashift

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
Top