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

LVL 1
gabrielPennybackReliability Business Tools Analyst IIAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
SANTABABYConnect With a Mentor Commented:
Your code at Line 4 does not have not correct syntax.
Replace with

If Worksheets(i).Name = "ACV" Or Worksheets(i).Name = "B773i4" Or Worksheets(i).Name = "JETZ" Or Worksheets(i).Name = "LEGACY"  Then

Open in new window


0
 
BusyMamaCommented:
I think if you Dim i as Integer?
0
 
reitzenCommented:
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

0
 
gabrielPennybackReliability Business Tools Analyst IIAuthor Commented:
I could swear I tried exactly what you posted, but obviously not exactly :-)  Thanks, SantaBaby.

- John
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.