I am trying to write a macro to look at cell A2 in each sheet in a workbook, and if there is no data in this cell then to delete the worksheet. (so I am left with only the sheets with comprehensive data on). I am looking at cell A2 not A1 as there is likely to be residual date in row 1.
The code I have tried to write which is obviously not working and for which I need help is below. Any help as to what else i need to include or a better way of doing this task would be gratefully received. (The reason I am trying to automate this seemingly simple task is that it will be one small part of a much larger macro.)
Happy christmas and thanking you in advance.
Sub DeleteSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If IsEmpty("A2") Then
ActiveSheet.Delete
End If
On Error Resume Next
Next ws
End Sub
The code I have tried to write which is obviously not working and for which I need help is below. Any help as to what else i need to include or a better way of doing this task would be gratefully received. (The reason I am trying to automate this seemingly simple task is that it will be one small part of a much larger macro.)
Happy christmas and thanking you in advance.
Sub DeleteSheets()
Dim ws As Worksheet
For Each ws In ActiveWorkbook.Worksheets
If IsEmpty("A2") Then
ActiveSheet.Delete
End If
On Error Resume Next
Next ws
End Sub