Hi,
I work for a company that owns multiple gas stations. I have a workbook that shows the financials for each station on its own worksheet. If the station does not have any activity within the period being reported, the worksheet is blank. I would like to create a macro that loops through the workbook and deletes all worksheets that are blank.
I found some code off the internet that does this but for some reason if there are two worksheets in a row that are blank, the second worksheet does not get deleted and I end up having to run the macro multiple times until all of the blank sheets are deleted.
Below is the code I'm using. Is there a way to remedy the problem of having to rerun the code?
Sub delete()
Dim i As Integer
Application.DisplayAlerts = False
On Error Resume Next
For i = 1 To Worksheets.Count
Sheets(i).Select
If Range("A3").Value = "" Then
Sheets(i).delete
End If
Next i
Application.DisplayAlerts = True
End Sub
Thanks for your help!
I work for a company that owns multiple gas stations. I have a workbook that shows the financials for each station on its own worksheet. If the station does not have any activity within the period being reported, the worksheet is blank. I would like to create a macro that loops through the workbook and deletes all worksheets that are blank.
I found some code off the internet that does this but for some reason if there are two worksheets in a row that are blank, the second worksheet does not get deleted and I end up having to run the macro multiple times until all of the blank sheets are deleted.
Below is the code I'm using. Is there a way to remedy the problem of having to rerun the code?
Sub delete()
Dim i As Integer
Application.DisplayAlerts = False
On Error Resume Next
For i = 1 To Worksheets.Count
Sheets(i).Select
If Range("A3").Value = "" Then
Sheets(i).delete
End If
Next i
Application.DisplayAlerts = True
End Sub
Thanks for your help!