-
Solved: Check if sheet name exists before deletion
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"
-
[VBA] On Error Resume Next
Sheets("Sheet3").Delete
[/VBA]
MVP (Excel 2008-2010)
Post a workbook with sample data and layout if you want a quicker solution.
To help indent your macros try Smart Indent
Please remember to mark threads 'Solved'
-
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.
[VBA]
On Error Resume Next
Sheets("Sheet3").Delete
On Error Goto 0
[/VBA]
-
cheers works a treat
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules