Code:
Sub DeleteBlankSheets()
Dim sh As Variant
Application.ScreenUpdating = False
Application.DisplayAlerts = False
On Error GoTo Exits:
For Each sh In Sheets
'IsChart checks, if sh is a Chart Object or some other object.
If Not IsChart(sh) Then
'CountA checks if there is any data in cells of the sheet
If Application.WorksheetFunction.CountA(sh.Cells) = 0 Then sh.Delete
End If
Next sh
Exits:
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub
Public Function IsChart(sh) As Boolean
Dim tmpChart As Chart
On Error Resume Next
Set tmpChart = Charts(sh.Name)
IsChart = IIf(tmpChart Is Nothing, False, True)
End Function
Comments