Reputation: 3
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
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