PDA

View Full Version : Solved: Check if sheet name exists before deletion



Immatoity
03-28-2006, 05:20 AM
I have searched and tried some code but I must be doing something stupid...

I want part of my macro to delete a sheet (only if it exists).. if it does exist delete it and carry on with rest of code, if it doesn't exist, simply carry on with the rest of the code.

The workbook has only one module in it... the sheet name it needs to check for and delete is "Adjusted Data"... the reason I need to delete it if its there is that the code afterwards copies another sheet's data and renames that to "Adjusted Data"..it will fail if the sheet name already exists.

Also, any code you kindly provide...let me know if I need a seperate module or whatever as thats where I get stuck... I would prefer it if it is in one..

NB the sub that copies and renames sheet is called "BlockedStockTidy"

mdmackillop
03-28-2006, 05:29 AM
On Error Resume Next
Sheets("Sheet3").Delete

Jacob Hilderbrand
03-28-2006, 08:49 AM
Also make sure that you reset the error handling after you are done.

This will simply delete the sheet or ignore the error if there is no sheet.


On Error Resume Next
Sheets("Sheet3").Delete
On Error Goto 0

Immatoity
03-28-2006, 11:28 PM
cheers works a treat:friends: