Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Unhiding and deleting multiple sheets based on their names

Posted on 2011-09-07
4
Medium Priority
?
237 Views
Last Modified: 2012-08-14
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

0
Comment
Question by:gabrielPennyback
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 7

Expert Comment

by:BusyMama
ID: 36498782
I think if you Dim i as Integer?
0
 
LVL 10

Accepted Solution

by:
SANTABABY earned 2000 total points
ID: 36498822
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
 
LVL 6

Expert Comment

by:reitzen
ID: 36498841
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
 
LVL 1

Author Closing Comment

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

- John
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
After seeing numerous questions for Dynamic Data Validation I notice that most have used Visual Basic to solve the problem. This suggestion is purely formula based and can be used in multiple rows.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question