PDA

View Full Version : [SOLVED:] Delete worksheets with blank cell



oam
10-17-2021, 03:03 PM
I have a file with multiple worksheet and I need a code that will delete only worksheet that cell C2 is blank/empty. In addition, the code will not delete constant worksheets named "Master", "Table of Contents", "Lookup", "Lookup Names", or "Names"

Thank you for any and all help

Paul_Hossler
10-17-2021, 05:07 PM
Not tested, but probably something like this




Option Explicit


'I have a file with multiple worksheet and I need a code that will delete only worksheets
'that have cell C2 is blank/empty. In addition, the code will not delete constant worksheets
'named "Master", "Table of Contents", "Lookup", "Lookup Names", or "Names"




Sub DeleteSomeWorksheets()
Dim ws As Worksheet

For Each ws In ActiveWorkbook.Worksheets
Select Case ws.Name
Case "Master", "Table of Contents", "Lookup", "Lookup Names", "Names"
Case Else
If Len(ws.Range("C2").Value) = 0 Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
End Select

Next
End Sub

oam
10-18-2021, 11:31 AM
Works Perfect,

Thank you so much!