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?
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
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
 
Upvote 0

Forum statistics

Threads
1,214,383
Messages
6,119,198
Members
448,874
Latest member
Lancelots

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
Back
Top