Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Deleting worksheets in a procedure


I am trying to create a small procedure to delete
worksheets if they are present. What is the code to test
if said sheet exists, and then delete it if it exists?

Thx MUCH in advance,
Al


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5
Default Deleting worksheets in a procedure

The following example deletes
sheets "Sheet5", "Sheet4", "Sheet1" if they exist. You can
easily modify to accomodate your sheet names and number.

Sub delete_sheets()
Dim sh(3) As String
sh(1) = "Sheet5"
sh(2) = "Sheet4"
sh(3) = "Sheet1"

On Error Resume Next
Application.DisplayAlerts = False

For i = 1 To 3
Sheets(sh(i)).Delete
Next

Application.DisplayAlerts = True
On Error GoTo 0
End Sub

Nikos Y. (nyannaco at in dot gr)
-----Original Message-----

I am trying to create a small procedure to delete
worksheets if they are present. What is the code to test
if said sheet exists, and then delete it if it exists?

Thx MUCH in advance,
Al


.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default Deleting worksheets in a procedure


That was PERFECT!!!

Thx MUCH!!

-----Original Message-----
The following example deletes
sheets "Sheet5", "Sheet4", "Sheet1" if they exist. You

can
easily modify to accomodate your sheet names and number.

Sub delete_sheets()
Dim sh(3) As String
sh(1) = "Sheet5"
sh(2) = "Sheet4"
sh(3) = "Sheet1"

On Error Resume Next
Application.DisplayAlerts = False

For i = 1 To 3
Sheets(sh(i)).Delete
Next

Application.DisplayAlerts = True
On Error GoTo 0
End Sub

Nikos Y. (nyannaco at in dot gr)
-----Original Message-----

I am trying to create a small procedure to delete
worksheets if they are present. What is the code to

test
if said sheet exists, and then delete it if it exists?

Thx MUCH in advance,
Al


.

.

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deleting worksheets in a procedure

Al,

See below:
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
'''''''
Public bSheetNameIsUnique, bSheetNameIsOK As Boolean

Sub DoSomething(ByVal SheetName As String)

If SheetIsUnique(NewSheetName) Then
GoTo DoAuto
Else
FileNameOnly = NewSheetName
GoTo DoManual
End If
End Sub
Function SheetIsUnique(ByVal SheetName As String)

On Error Resume Next
Dim ErrMsg As String
bSheetNameIsUnique = True
For iSheetCount = 1 To Sheets.Count
If LCase(Sheets(iSheetCount).Name) =
LCase(SheetName) Then
bSheetNameIsUnique = False
Exit For
End If
Next
SheetIsUnique = bSheetNameIsUnique

End Function
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
'''''''''''''''''''''''''''''''''''''''''''''''''' ''''''''''''''''''''''''''
'''''''
Hope that helps
Philippe
"Al" wrote in message
...

I am trying to create a small procedure to delete
worksheets if they are present. What is the code to test
if said sheet exists, and then delete it if it exists?

Thx MUCH in advance,
Al




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
Macro for Deleting Worksheets andiam24 Excel Discussion (Misc queries) 2 April 2nd 09 03:47 PM
Deleting worksheets David Excel Discussion (Misc queries) 2 January 19th 07 08:19 PM
Deleting blank worksheets Lvenom Excel Worksheet Functions 3 June 15th 06 12:28 AM
Help deleting worksheets Wilhelmutt Excel Discussion (Misc queries) 2 April 19th 05 03:23 AM


All times are GMT +1. The time now is 01:56 PM.

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

About Us

"It's about Microsoft Excel"