Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Delete all but 1 sheet in workbook

A2K

Using code, how do I loop through all the worksheets in a workbook and
delete all but the first one, "Sheet1"

Thanks,

Charles D Clayton Jr

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Delete all but 1 sheet in workbook

try
Sub deleteallsheets()
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Name < "Sheet1" Then ws.Delete
Next
Application.DisplayAlerts = True
End Sub

--
Don Guillett
SalesAid Software

"cdclayton" wrote in message
ups.com...
A2K

Using code, how do I loop through all the worksheets in a workbook and
delete all but the first one, "Sheet1"

Thanks,

Charles D Clayton Jr



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Delete all but 1 sheet in workbook

Thanks for your help. One more question, is it possible to have this
work no matter what the sheet is renamed to?

Thanks,

Charles D Clayton Jr

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Delete all but 1 sheet in workbook

try
Sub deleteallsheets()
Application.DisplayAlerts = False
For Each ws In Worksheets
If ws.Index < 1 Then ws.Delete
Next
Application.DisplayAlerts = True
End Sub

--
Don Guillett
SalesAid Software

"cdclayton" wrote in message
oups.com...
Thanks for your help. One more question, is it possible to have this
work no matter what the sheet is renamed to?

Thanks,

Charles D Clayton Jr



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
Delete rows from one sheet containing deatils on the second sheet [email protected] New Users to Excel 4 September 6th 07 11:10 AM
How to Delete a Range in Closed Workbook (to Replace Delete Query) [email protected] Excel Discussion (Misc queries) 1 March 8th 06 10:10 AM
Automatically Delete WorkBook 2 modules by using Workbook 1 module ddiicc Excel Programming 5 July 27th 05 12:53 PM


All times are GMT +1. The time now is 02:33 AM.

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"