Lookup del

chiragggg

Board Regular
Joined
Mar 18, 2010
Messages
197
Hi,

I have a a list of worksheet names in a worsheet. e/g column Z.

The list is the worksheet names that need to be deleted in the workbook,

I wanted a macro that looks at these worksheets and deletes any worksheet names that are on that list...

Any suggestions?
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).

Special-K99

Well-known Member
Joined
Nov 7, 2006
Messages
8,350
This works, assumes list is on Sheet1 in column A

You'll probably want to uncomment the "Application.DisplayAlerts" below so that you dont get prompted each time a worksheet is deleted

Code:
Sub k1()

'Application.DisplayAlerts = False

For Each c In Worksheets("Sheet1").Range("a1:a2").Cells
Sheets(c.Value).Delete
Next c

'Application.DisplayAlerts = True

End Sub
 

chiragggg

Board Regular
Joined
Mar 18, 2010
Messages
197
Does "c" variable need to be defined?

If I had the list in column Z could I use Z1:z4 as the range?
 

chiragggg

Board Regular
Joined
Mar 18, 2010
Messages
197
Get an error 91

Object variable or With block variable not set (Error 91)

Code below


Sub finaldelsheets()

Dim Ws As Worksheet
Dim c As Range


'select worksheet lookup

Sheets("Approved").Select
Dim MyName As String
MyName = Range("c2")

'deletes analysis sheets that are selected at start of process

Application.DisplayAlerts = False

For Each c In Ws("MyName").Range("z1:z4").Cells
Sheets(c.Value).Delete
Next c

Application.DisplayAlerts = True


End Sub
 

Watch MrExcel Video

Forum statistics

Threads
1,133,720
Messages
5,660,501
Members
418,580
Latest member
IrishDave2137

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