VBA/Macro to delete particular sheets based on condition

bakarken

Board Regular
Joined
Sep 23, 2016
Messages
50
Office Version
  1. 2019
Platform
  1. Windows
Hi all

I am preparing a spreadsheet which will have several sheets and a 'master' sheet. The user will first look at the master sheet and enter 'YES' or 'NO' as text in certain cells. I would like a macro where if the user types 'YES', CERTAIN sheets will be deleted.

For example;

If cell E30 (in 'MASTER' sheet) = 'YES', sheets 'Sheet A' and 'Sheet C' will automatically be deleted.
or if cell E40 (in 'MASTER' sheet) = 'YES', sheets 'Sheet B' and 'Sheet D' will automatically be deleted.

I am useless with macros, so if anyone with a response could tell me in WHAT sheet to paste the code and how to activate this, that would be great.

Much appreciated.
 
That seems to have done the trick!

Thank you so much for the help I shall be eternally grateful
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Gallen, I'm trying to do something similar and stumbled across your code. It works well, but I was hoping to make something a little more dynamic.
I want a macro that will delete specified sheets based on a specified category in a table of contents. Basically, on the main Instructions tab for the workbook, there is a table that lists every tab in the workbook, its purpose, and whether it is used at Interim or Year-End. On the Instructions tab is also a cell that asks what period it is (Interim / Year-End). I want the macro to delete any Year-End tab when the cell on the Instructions sheet is set to Interim. Is that possible?
 
Upvote 0

Forum statistics

Threads
1,223,993
Messages
6,175,836
Members
452,674
Latest member
psion2600

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