VBA Excel - Excluindo Abas onde não tem qualquer conteúdo - Delete/Remove Blank/Empty Worksheets

Blog Office VBA | Blog Excel | Blog Access |
Inline image 1

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
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
End Sub

Function IsChart As Boolean
    Dim tmpChart As Chart
    On Error Resume Next
    Set tmpChart = Charts(sh.Name)
    IsChart = IIf(tmpChart Is Nothing, False, True)
End Function

Tags: VBA, aba, worksheet, delete, excluindo, blank, empty, sheet

✔ VBA Brazil®

✔ VBA Brazil®
Related Posts Plugin for WordPress, Blogger...
diHITT - Notícias