HL8
HL8

Reputation: 1419

Delete a sheet where name starts with a certain value

I want to delete a sheet where the name starts with "data as at". I've used the following but not working.

For Each SheetExists In Worksheets
    If Left(SheetExists.Name, 10) = "Data as at" Then
        Application.DisplayAlerts = False
        Sheets(Left("Data as at", 10)).Delete
        Application.DisplayAlerts = True
        Exit For
    End If
Next SheetExists

It comes back with a subscript error for the following line.

Sheets(Left("Data as at", 10)).Delete

Upvotes: 2

Views: 6451

Answers (1)

Kirill Leontev
Kirill Leontev

Reputation: 10941

Sheets(Left("Data as at", 10)).Delete

SheetExists.Delete

Upvotes: 3

Related Questions