Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Delete sheet without prompt

How can I delete a sheet without a message box prompting for the user to confirm the deletion of the sheet? Also, is there a way to rename a sheet without it defaulting to "sheet1" or the next number? In other words, if "sheet1" already exists when I add a new sheet it will default to "sheet2" and the following code will generatte an error

Sheets("Import").Selec
ActiveWindow.SelectedSheets.Delet
Sheets.Ad
Sheets("Sheet1").Name = "Import

Thank

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Delete sheet without prompt

Hi chad

Application.DisplayAlerts = False
'delete code
Application.DisplayAlerts = True


This example will not give a error if it exist

On Error Resume Next
Sheets("Sheet1").Name = "Import"
On Error GoTo 0



--
Regards Ron de Bruin
http://www.rondebruin.nl


"chad" wrote in message ...
How can I delete a sheet without a message box prompting for the user to confirm the deletion of the sheet? Also, is there a way

to rename a sheet without it defaulting to "sheet1" or the next number? In other words, if "sheet1" already exists when I add a new
sheet it will default to "sheet2" and the following code will generatte an error.

Sheets("Import").Select
ActiveWindow.SelectedSheets.Delete
Sheets.Add
Sheets("Sheet1").Name = "Import"

Thanks



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Delete sheet without prompt

Here is one way for the second part

iNext = Activeworkbook.Worksheets.Count + 1
Do Until Not SheetExists("Sheet" & iNext)
iNext = iNext + 1
Loop
Woeksheets.Add.Name = "Sheet" & iNext



Function SheetExists(Filename As String)
Dim oSh As Worksheet
On Error Resume Next
Set oSh = ActiveWorkbook.Worksheets(Filename)
On Error GoTo 0
SheetExists = Not oSh Is Nothing
End Function


--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"chad" wrote in message
...
How can I delete a sheet without a message box prompting for the user to

confirm the deletion of the sheet? Also, is there a way to rename a sheet
without it defaulting to "sheet1" or the next number? In other words, if
"sheet1" already exists when I add a new sheet it will default to "sheet2"
and the following code will generatte an error.

Sheets("Import").Select
ActiveWindow.SelectedSheets.Delete
Sheets.Add
Sheets("Sheet1").Name = "Import"

Thanks



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9
Default Delete sheet without prompt

Thanks all.
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
Delete ROW on Sheet#1 corupts data on Sheet#2 Duane Excel Worksheet Functions 4 February 11th 10 07:53 PM
Delete values in sheet 2 that arre found in sheet 1 np Excel Discussion (Misc queries) 1 December 10th 09 07:21 PM
Unwanted Prompt When Saving a Protected Sheet in 2007 faraway Excel Discussion (Misc queries) 0 May 6th 09 12:46 PM
How do I disable save prompt when exiting a sheet? Copter32 Excel Discussion (Misc queries) 7 March 12th 08 04:25 PM
Delete rows from one sheet containing deatils on the second sheet [email protected] New Users to Excel 4 September 6th 07 11:10 AM


All times are GMT +1. The time now is 07:12 AM.

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"