I have a spreadsheet that has been working perfectly for months. Now, intermittently, when I attempt to move of a row (by entering "Yes" in the column), I get this error
Run-time error'-2147417848 (80010108)':
Method 'Insert' of object 'Range' failed
I have 9 sheets. All sheets have the following code onto the Archive Tab:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDest As Range
Set rngDest = Worksheets("Archive").Range("rngDest")
Dim rngTrigger As Range
' Limit the trap area to range of cells in which completed dates are entered as defined above
If Not Intersect(Target, Range("rngTrigger")) Is Nothing Then
' Only trigger if the value entered is TRUE
If Target.Value = "Yes" Then
'Ensure subsequent deletion of 'moved' row does NOT cause the Change Event to run again and get itself in a loop!
Application.EnableEvents = False
Target.EntireRow.Select
Selection.Cut
rngDest.Insert Shift:=xlDown
Selection.Delete
' Reset EnableEvents
Application.EnableEvents = True
End If
End If
On Error Resume Next
If Not Intersect(Target, Range("B:B")) Is Nothing Then
With Worksheets("Home Office").Sort
.SortFields.Clear
.SortFields.Add Key:=Range("B:B"), _
SortOn:=xlSortOnValues, _
Order:=xlAscending, _
DataOption:=xlSortNormal
.SetRange Range("A5:F25")
.Header = xlNo
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End If
End Sub
The code stops on the bolded line above, then in the bottom left hand corner of the screen it says "Select Destination and click enter or choose Paste".
If I go nowhere except to the top Menu and click Paste, Excel craps out, recovers and when it comes back, the Row has been moved to the Archive.
I checked the code over and over. There isn't a clear reason why it should work for months and now doesn't....or that it should work 4 or 5 times, different sheets, different rows, then gives the error.
Additionally, I've checked the rngDest Named Range. It correctly shows the next blank row on the page as =ARCHIVE!$59:$59, and increased with each add, correctly. Everything appears to be correct...and has been working. Until today.
Could my code to sort have anything to do with it?
I can upload the sheet if someone would like to test it.
ANY help would be much appreciated. Upper management uses this sheet and I would like to get it working before it happens to one of them.
Thanks so much,
LBinGA
Bookmarks