If Worksheet exists, delete it, then re-add it

  • Thread starter Thread starter Cheryl
  • Start date Start date
C

Cheryl

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
 
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
 
That worked perfectly!

Thank you.

Ryan H said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top