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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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
 
Upvote 0
Does "c" variable need to be defined?

If I had the list in column Z could I use Z1:z4 as the range?
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,438
Members
449,083
Latest member
Ava19

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