View Single Post
  #3   Report Post  
Posted to microsoft.public.excel.programming
Cheryl Cheryl is offline
external usenet poster
 
Posts: 144
Default If Worksheet exists, delete it, then re-add it

That worked perfectly!

Thank you.

"Ryan H" wrote:

This should work for you. Hope this helps! If so, let me know, click "YES"
below.

Option Explicit

Sub DeleteSheet()

' delete sheet if it exists
On Error Resume Next
Sheets("Score").Delete
On Error GoTo 0

' add new sheet
Sheets.Add After:=Sheets(Sheets.Count)

' rename sheet
Sheets(Sheets.Count).Name = "Score"

End Sub
--
Cheers,
Ryan


"Cheryl" wrote:

Working in Excel 2007, I am writing a program to create a scoresheet to keep
track of scores for a game my family plays. Since a lot of the set-up is
based on the number of players, the first thing I want to do if check to see
if sheet called "Score" is there, left over from a previous game, and if so,
delete. The program will then create a new worksheet, "Score". I've seen a
lot of help on how to create a new worksheet if one doesn't already exist,
but not on how to delete an existing one, then add it again.

Can anyone help this newbie?

Thanks