Link to home
Start Free TrialLog in
Avatar of John Carney
John CarneyFlag for United States of America

asked on

Unhiding and deleting multiple sheets based on their names

I get a type mismatch error on line 3 in the code below. What is the proper way to write that line?

Thanks,
John
Sub RemoveSheets()
Dim i As Long, ws As Worksheet
For i = 1 To ActiveWorkbook.Worksheets.Count
    If Worksheets(i).Name = "ACV" Or "B773i4" Or "JETZ" Or "LEGACY" Then
    Worksheets(i).Visible = True
    Worksheets(i).Delete
    End If
Next
End Sub

Open in new window

Avatar of BusyMama
BusyMama
Flag of United States of America image

I think if you Dim i as Integer?
ASKER CERTIFIED SOLUTION
Avatar of SANTABABY
SANTABABY
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Unless you need to know the sheet number, it would be better to loop over the worksheets collection.


dim ws as worksheet
for each ws in worksheets
    if ws.name = "ACV" then
        ...
    end if
next ws

Open in new window

Avatar of John Carney

ASKER

I could swear I tried exactly what you posted, but obviously not exactly :-)  Thanks, SantaBaby.

- John