VBA to delete worksheets

  • Thread starter Mark_F via OfficeKB.com
  • Start date
M

Mark_F via OfficeKB.com

Greetings, all.

Would someone help me write code to for my workbook to delete a worksheet(s)
if I have two empty cells? For example, if I have a date cell AND a job
number cell empty I would need that worksheet deleted.

Any help would be much appreciated.
 
L

Luke M

Perhaps something like this:


Sub DeleteSheets()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
'Change ranges as appropriate
If ws.Range("A4") = "" And ws.Range("B4") = "" Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next
End Sub
 
M

Mark_F via OfficeKB.com

Thank you, Luke, for your response. I will give it a try!

Luke said:
Perhaps something like this:

Sub DeleteSheets()
Dim ws As Worksheet

For Each ws In ThisWorkbook.Worksheets
'Change ranges as appropriate
If ws.Range("A4") = "" And ws.Range("B4") = "" Then
Application.DisplayAlerts = False
ws.Delete
Application.DisplayAlerts = True
End If
Next
End Sub
Greetings, all.
[quoted text clipped - 3 lines]
Any help would be much appreciated.
 
Top