Excel 2007 error: Method 'Delete' of object 'Range' failed

lottrup

New Member
Joined
Mar 9, 2009
Messages
16
Hi,

I have written a sub with the purpose of finding rows based on a critieria, copying the rows to another worksheet and deleting the original row.

The code:
Code:
Sub MoveToIgangvaerende()
'
' Flytter opgaven til sheetet Igangværende projekter
'
Dim i, j, Index As Integer
Forfra:
For i = -1 To 1000
    If Sheets("Pipeline").Cells(3 + i, 20) = "Ja" Or Sheets("Pipeline").Cells(3 + i, 20) = "ja" Then
        Sheets("Pipeline").Select
        Cells(3 + i, 14) = 1
        Cells(3 + i, 18).EntireRow.Select
        Selection.Cut
        
        Sheets("Igangværende").Select
        For j = 1 To 1000
            If IsEmpty(Cells(3 + j, 1)) Then
                Cells(3 + j, 1).EntireRow.Select
                Selection.Insert Shift:=xlDown
                
                Index = j
                j = 1000
            End If
        Next j
        Cells(Index, 14) = 1
        'Cells(Index, 15) = 0
        
        Sheets("Pipeline").Cells(3 + i, 18).EntireRow.Delete
        GoTo Forfra
        
    End If
Next i
End Sub

I get the error message "Method 'Delete' of object 'Range' failed" at the line "Sheets("Pipeline").Cells(3 + i, 18).EntireRow.Delete".

The sub has previously worked perfectly fine.

Really hope someone can help me out on this.
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
If you have protected the sheet since previously worked perfectly fine, you will have to add unprotect sheet at the begiining of your code and at the end protect the sheet again
 
Upvote 0
I forgot to mention to check Workbook protection as well. Same would apply if Workbook is Protected.
 
Upvote 0
That code is quite hard to follow, at one point you seem to be jumping with Goto out of a loop to just start the loop all over again.

It also changes the value of one of the loop variables, j, within it's own loop.

What exactly is the code mean to do?

PS Why does the loop start at -1?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,728
Members
452,939
Latest member
WCrawford

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