Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Delete all blank worksheets?


Is it possible to use a macro to delete all the worksheets inmy workboo
that do not contain any data?

Everytime i try to come up with something i end up losing somethin
important so would be grateful for any hel

-----------------------------------------------
~~ Message posted from http://www.ExcelTip.com
~~View and post usenet messages directly from http://www.ExcelForum.com

~~Now Available: Financial Statements.xls, a step by step guide to creating financial statements
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 85
Default Delete all blank worksheets?

Ian,

Try This:

It looks for the number of cells in the sheet's used range, and (when blank)
that is equal to 1. If the one cell has nothing in it, then the sheet is
empty and can be deleted.

Alex J

Sub DeleteBlankWS()
Application.DisplayAlerts = False
On Error Resume Next
For Each ws In ThisWorkbook.Worksheets
cellcount = ws.UsedRange.Cells.Count
If cellcount = 1 Then
If ThisWorkbook.Worksheets.Count 1 Then
If ws.UsedRange.Value = "" Then
Rtnn = MsgBox("Deleting Worksheet ["
& ws.Name & "]", vbExclamation + vbOKCancel, "Delete Blank Worksheets")
If Rtnn = vbOK Then ws.Delete
End If
Else
Rtnn = MsgBox("Cannot Delete Last Worksheet
in Workbook", vbExclamation + vbOK, "Delete Blank Worksheets")
End If
End If
Next ws
Application.DisplayAlerts = True
End Sub




"ian123" wrote in message
...

Is it possible to use a macro to delete all the worksheets inmy workbook
that do not contain any data?

Everytime i try to come up with something i end up losing something
important so would be grateful for any help


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 493
Default Delete all blank worksheets?

A slightly different alternative:

Public Sub DeleteBlankWS()
Dim ws As Worksheet
With Application
.ScreenUpdating = False
.DisplayAlerts = False
End With
For Each ws In ActiveWorkbook.Worksheets
If Application.CountA(ws.Cells) = 0 Then
If ActiveWorkbook.Worksheets.Count 1 Then
ws.Delete
Else
MsgBox "Could not delete last worksheet."
End If
End If
Next ws
With Application
.ScreenUpdating = True
.DisplayAlerts = True
End With
End Sub

In article ,
"Alex J" wrote:

Ian,

Try This:

It looks for the number of cells in the sheet's used range, and (when blank)
that is equal to 1. If the one cell has nothing in it, then the sheet is
empty and can be deleted.

Alex J

Sub DeleteBlankWS()
Application.DisplayAlerts = False
On Error Resume Next
For Each ws In ThisWorkbook.Worksheets
cellcount = ws.UsedRange.Cells.Count
If cellcount = 1 Then
If ThisWorkbook.Worksheets.Count 1 Then
If ws.UsedRange.Value = "" Then
Rtnn = MsgBox("Deleting Worksheet ["
& ws.Name & "]", vbExclamation + vbOKCancel, "Delete Blank Worksheets")
If Rtnn = vbOK Then ws.Delete
End If
Else
Rtnn = MsgBox("Cannot Delete Last Worksheet
in Workbook", vbExclamation + vbOK, "Delete Blank Worksheets")
End If
End If
Next ws
Application.DisplayAlerts = True
End Sub




"ian123" wrote in message
...

Is it possible to use a macro to delete all the worksheets inmy workbook
that do not contain any data?

Everytime i try to come up with something i end up losing something
important so would be grateful for any help


------------------------------------------------
~~ Message posted from http://www.ExcelTip.com/
~~View and post usenet messages directly from http://www.ExcelForum.com/

~~Now Available: Financial Statements.xls, a step by step guide to

creating financial statements


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
How to delete blank worksheets Keep_It_Simple_Stupid Excel Worksheet Functions 1 January 23rd 08 09:35 AM
Delete Blank Rows Code - Multiple Worksheets - Multiple Documents BenS Excel Discussion (Misc queries) 3 June 29th 07 12:20 AM
where can I down Blank Worksheets, blank stmt. of account forms carmen Excel Discussion (Misc queries) 2 January 15th 07 03:03 PM
Is there a easy way to delete blank lines to clean up worksheets? jdf5 Excel Worksheet Functions 2 June 4th 06 06:05 PM
"BLANK" - need to delete anjgoss Excel Worksheet Functions 3 August 25th 05 05:31 PM


All times are GMT +1. The time now is 08:57 PM.

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"