vba to delete tabs

I have a macro that deletes tabs. It works however it pops up with a confirmation to delete the data in the tabs. How can I do about deleting the tabs and not prompting me?

Also, how can I go about editing to delete only if the tab exsists. IE, if I don't have a GI tab, below errors out.

Thanks!

Sub clear()
    Sheets("GI").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("FS").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("GO").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("Filtered from Results").Select
    ActiveWindow.SelectedSheets.Delete
    Sheets("RUN").Select
End Sub

Open in new window

eastsidemarketAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Kyle AbrahamsSenior .Net DeveloperCommented:
Application.EnableEvents = false
'rest of code
Application.EnableEvents = true


http://vbadud.blogspot.com/2007/03/disabling-excel-events.html
0
eastsidemarketAuthor Commented:
ged325 - just tried that.
still get an excel prompt:
"data may exist in the sheet(s) selected for deletion. To permanently delete the data, press Delete"

how can i auto "delete" these prompts?
0
[ fanpages ]IT Services ConsultantCommented:
Hi,

The first advice you received was incorrect.

You need to set:
Application.DisplayAlerts = False

Then delete the worksheets.

Finally:
Application.DisplayAlerts = True

However, you can improve your code as follows:

Sub clear()
 
  Application.DisplayAlerts = False

  Worksheets("GI").Delete
  Worksheets("FS").Delete
  Worksheets("GO").Delete
  Worksheets("Filtered from Results").Delete

  Application.DisplayAlerts = True

  Worksheets("RUN").Select

End Sub

Open in new window

Furthermore:
Sub clear()
 
  Application.DisplayAlerts = False

  Worksheets(Array("GI", "FS", "GO", "Filtered from Results")).Delete

  Application.DisplayAlerts = True

  Worksheets("RUN").Select

End Sub

Open in new window


BFN,

fp.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
eastsidemarketAuthor Commented:
Perfect. Worked like a charm!
0
[ fanpages ]IT Services ConsultantCommented:
:) Good luck with the rest of your project.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.