VBA deleting a worksheet based on a cell

Toya Mack

New Member
Joined
Jul 5, 2015
Messages
2
Hello,

I am trying to create a VBA to delete a worksheet based on a cell. I know the VBA to delete an active worksheet, but in this case I am working with a template that contains 34 worksheets and based on contracts I may not need them all "every time". So I would like to create a VBA that after I have put the information in the workbook and did not enter information in a cell on a worksheet to run the VBA to delete that worksheet.....is this possible?
 

Some videos you may like

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

vaskov17

Well-known Member
Joined
Apr 27, 2011
Messages
920
all sheets with A1 empty will be deleted, change the range to whatever you need

Code:
Sub delSheets()
    Dim wks As Worksheet
    
    Application.DisplayAlerts = False
    For Each wks In ActiveWorkbook.Worksheets
        If wks.Range("A1") = "" Then
            wks.Delete
        End If
    Next
    Application.DisplayAlerts = True
End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,123,303
Messages
5,600,857
Members
414,407
Latest member
Zaner0445

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top