marklee800
New member
- Joined
- Nov 24, 2013
- Messages
- 1
- Reaction score
- 0
- Points
- 0
Hi All,
I am trying to delete some worksheets within a workbook from a list containing the names of worksheets to be deleted, listed in column B2:B30, in sheet titled " Sheetlist". I obtained the following code from a thread, the code seems to work if column B in the specified range are all populated. If it is empty, as in the example, the code does no work.
In "SheetList" sheet, cell A2 onwards in column A contain all the names within the workbook. Cell B2 onwards in column B to cell B30 will be the area which I specify the sheets I need to delete.
Can you please help to modify the code so that the macro will loop through each cell from B2:B30 eventhough it is empty, and delete worksheets name which are listed?
Thanks.
Mark
Sub DeleteSheets()
Dim i As Long
For i = 2 To 30
Sheets("SheetList").Select
Application.DisplayAlerts = False
Worksheets(CStr(ActiveSheet.Cells(i, 2).Value)).Delete
Application.DisplayAlerts = True
Next i
End Sub
I am trying to delete some worksheets within a workbook from a list containing the names of worksheets to be deleted, listed in column B2:B30, in sheet titled " Sheetlist". I obtained the following code from a thread, the code seems to work if column B in the specified range are all populated. If it is empty, as in the example, the code does no work.
In "SheetList" sheet, cell A2 onwards in column A contain all the names within the workbook. Cell B2 onwards in column B to cell B30 will be the area which I specify the sheets I need to delete.
Can you please help to modify the code so that the macro will loop through each cell from B2:B30 eventhough it is empty, and delete worksheets name which are listed?
Thanks.
Mark
Sub DeleteSheets()
Dim i As Long
For i = 2 To 30
Sheets("SheetList").Select
Application.DisplayAlerts = False
Worksheets(CStr(ActiveSheet.Cells(i, 2).Value)).Delete
Application.DisplayAlerts = True
Next i
End Sub