Lionel Zed
Lionel Zed

Reputation: 3

Error while deleting sheet. Runtime Error 1004 : delete method of range class failed

I am trying to delete a sheet selected from a list box. The msgbox commands displaying the sheet names are correct but I seem to get an error which is as below:

Runtime Error 1004: Delete method of range class failed.

Here is my code.

If ListBox2.Selected(i) Then
        Worksheets(ListBox2.List(i)).Unprotect "asdf"
        Worksheets(ListBox2.List(i)).Delete
        MsgBox ListBox2.List(i)
        sht = ListBox2.List(i) + "_Graph"
        Worksheets(sht).Unprotect "asdf"
        MsgBox sht
        Worksheets(sht).Delete
        Worksheets("Report").Rows(ListBox2.ListIndex + 2).Delete
        MsgBox "KC " + ListBox2.List(i) + " Removed!"

    End If

Upvotes: 0

Views: 913

Answers (1)

Michał Turczyn
Michał Turczyn

Reputation: 37500

Try this:

Worksheets("Report").Rows(ListBox2.ListIndex + 2).EntireRow.Delete

instead of:

Worksheets("Report").Rows(ListBox2.ListIndex + 2).Delete

(second to last line).

Upvotes: 1

Related Questions