Tony
Tony

Reputation: 43

Why is this "Delete Method of Range class failed" error popping up?

I am trying to figure out why this "Delete Method of Range Class" error is popping up. It does not always occur when this macro runs, which makes it all the more perplexing.

Can anybody explain this?

Sub ResetSheet()
If WindowsOS Then

    '*******************************************************************************************************'
'Resets the Data sheet.  Called by the resetSheetButton procedure (located in module: m7_Macros1_5).    '
'Also called by the OkCommandButton_Click procedure in the OnOpenUserForm form.                         '
    '*******************************************************************************************************'

Application.EnableEvents = False

Sheet4.Visible = True
Sheet4.Activate
Sheet4.Select
Sheet4.Rows("2:101").Select
Selection.Copy

'TC Edit
Sheet1.Activate
Sheet1.Range("A2").PasteSpecial (xlPasteAll)
'Sheet1.Paste
Sheets("Data").Select
Sheet1.Rows("102:10000").EntireRow.Delete
Sheet4.Visible = False

'TC Edit 2.0 - Adding code to reset the exception checkboxes
If WindowsOS Then
    Call resetCheckBoxes
End If

Application.EnableEvents = True

This is the macro code that causes the error (sometimes)

This is the error pop-up

Upvotes: 2

Views: 15552

Answers (1)

Karthick Gunasekaran
Karthick Gunasekaran

Reputation: 2713

try with below simplified code

Sub ResetSheet()
    'If WindowsOS Then
    Application.EnableEvents = False
    With Worksheets("Sheet4")
        .Visible = True
        .Rows("2:101").Copy Worksheets("Sheet1").Range("A2")
    End With
    With Worksheets("Sheet1")
        .Rows("102:101").EntireRow.Delete
    End With
    Worksheets("Sheet4").Visible = False
    If windowsOS Then
        Call resetCheckBoxes
    End If
    Application.EnableEvents = True
End Sub

Upvotes: 2

Related Questions