Macro for Deleting Worksheets
Hi Gary,
Thanks for the code but I couldn't figure if it assumed the tab name was the
same as the column name? And I tried it but got a subscript out of range
error which is the same error I got from the code I was trying before, which
follows:
The user selection mechanism is a checkbox located in row 6 (hence the
Value=FALSE) but I'm sure there's a better way.
Sub CommandButton1_Click()
Dim BTN As Button
Set BTN = ActiveSheet.Buttons(Application.Caller)
'deletes unused tabs and confirm delete dialog
Application.DisplayAlerts = False
If Workbooks("Sheet1").Range("d6").Value = False Then
Worksheets(Array("Sheet2", "Sheet10")).Delete
End If
If Workbooks("Sheet1").Range("e6").Value = False Then
Worksheets(Array("Sheet4", "Sheet12")).Delete
End If
If Workbooks("Sheet1").Range("f6").Value = False Then
Worksheets("Sheet6").Delete
End If
If Workbooks("Sheet1").Range("g6").Value = False Then
Worksheets(Array("Sheet3", "Sheet5", "sheet9")).Delete
End If
If Workbooks("Sheet1").Range("i6").Value = False Then
Worksheets("sheet21").Delete
End If
If Workbooks("Sheet1").Range("T6").Value = False Then
Worksheets(Array("Sheet7", "Sheet15", "sheet17", "sheet18")).Delete
End If
End Sub
|