Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
if workbooks exists delete | Excel Programming | |||
If Pivot Table Exists, Delete on Close | Excel Programming | |||
If sheet exists, delete | Excel Programming | |||
Check for a shape - then change or delete it if it exists | Excel Programming | |||
If worksheet exists delete | Excel Programming |