VBA Delete current work sheet if not a specific title

mrmrf

New Member
Joined
Jun 3, 2019
Messages
34
Hi.

Im needing help for VBA to delete current work sheet if not a specific name.

Quite a lot of examples out, but can't seem to adapt.

Thanks.
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Code:
Application.DisplayAlerts = False
If ActiveSheet.Name = "Sheet1" Then ActiveSheet.Delete
Application.DisplayAlerts = True
 
Upvote 0
Code:
Application.DisplayAlerts = False
If ActiveSheet.Name = "Sheet1" Then ActiveSheet.Delete
Application.DisplayAlerts = True
The OP said "delete current work sheet if not a specific name", so I think your equal sign (=) should be a not equal sign (<>).
 
Upvote 0
Thanks footoo, but what if i dont want it to delete the active sheet if its a specific name.

For example, i could have sheet1, sheet2, sheet3. Each page has this code to delete, but i dont want it to delete if the name is sheet1
 
Upvote 0
Actually, the code works and delets as require, but i get this error

run-time error '-2147221080 (800401a8) automation error

Not sure why?
 
Upvote 0
Do you have the macro containing the code in the sheet module being deleted?
If so, put in a normal module instead.
 
Upvote 0

Forum statistics

Threads
1,213,510
Messages
6,114,034
Members
448,543
Latest member
MartinLarkin

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