Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default If Worksheet exists, delete it, then re-add it

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 489
Default If Worksheet exists, delete it, then re-add it

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
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

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
if workbooks exists delete Stephen Excel Programming 4 December 4th 09 03:25 PM
If Pivot Table Exists, Delete on Close ryguy7272 Excel Programming 4 December 15th 08 12:10 PM
If sheet exists, delete Darin Kramer Excel Programming 2 August 20th 07 07:01 PM
Check for a shape - then change or delete it if it exists Mona-ABE Excel Programming 2 May 30th 07 05:37 PM
If worksheet exists delete cereldine[_43_] Excel Programming 4 July 13th 06 05:26 PM


All times are GMT +1. The time now is 09:10 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"