ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to delete unwanted sheets (https://www.excelbanter.com/excel-programming/317348-how-delete-unwanted-sheets.html)

N E Body[_17_]

how to delete unwanted sheets
 

Hello everyone

I want to clear a workbook of all but 3 worksheets on opening th
workbook.
Unfortunately I do not know the names of the sheets to delete -
simply want to keep "Log", "Data", Lists" - There may be as many as 1
unwanted sheets.

Could anyone suggest code to do this?

TIA

Kenny
Various combinations of
Win Me, 2000,XP
Office 97 and 200

--
N E Bod
-----------------------------------------------------------------------
N E Body's Profile: http://www.excelforum.com/member.php...fo&userid=1126
View this thread: http://www.excelforum.com/showthread.php?threadid=31868


mangesh_yadav[_203_]

how to delete unwanted sheets
 

Sub SheetDelete()

For Each sht In Worksheets

If sht.Name < "Log" And sht.Name < "Data" And sht.Name < "Lists
Then
sht.Delete
End If

Next

End Sub


but the problem is this will prompt you whether to delete or not. Ther
is a way around this which I am not remembering at the moment

- Manges

--
mangesh_yada
-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=31868


mangesh_yadav[_204_]

how to delete unwanted sheets
 

ok. here it is. Use

Sub DeleteSheet()

Application.DisplayAlerts = False

For Each sht In Worksheets
If sht.Name < "Log" And sht.Name < "Data" And sht.Name <
"Lists" Then
sht.Delete
End If

Next

Application.DisplayAlerts = True
End Su

--
mangesh_yada
-----------------------------------------------------------------------
mangesh_yadav's Profile: http://www.excelforum.com/member.php...fo&userid=1047
View this thread: http://www.excelforum.com/showthread.php?threadid=31868


N E Body[_18_]

how to delete unwanted sheets
 

Thanks for you help - that did the trick!

Kenn

--
N E Bod
-----------------------------------------------------------------------
N E Body's Profile: http://www.excelforum.com/member.php...fo&userid=1126
View this thread: http://www.excelforum.com/showthread.php?threadid=31868



All times are GMT +1. The time now is 04:01 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com