Solved

Unhiding and deleting multiple sheets based on their names

Posted on 2011-09-07
4
190 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
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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
The view will learn how to download and install SIMTOOLS and FORMLIST into Excel, how to use SIMTOOLS to generate a Monte Carlo simulation of 30 sales calls, and how to calculate the conditional probability based on the results of the Monte Carlo …
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.

895 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now