Solved

Unhiding and deleting multiple sheets based on their names

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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Sparklines have been introduced with Excel 2010 and are a useful tool for creating small in-cell charts, used for example in dashboards. Excel 2010 offers three different types of Sparklines: Line, Column and Win/Loss. What it does not offer is a…
Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

743 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

13 Experts available now in Live!

Get 1:1 Help Now