check if certain worksheet exists and delete

asdfasdf

New Member
Joined
Aug 19, 2009
Messages
9
does anyone know how to check if a worksheet exists called "workingdata" and delete it if it does?
If the workingdata worksheet does not exist i just want to carry on with the rest of the things i've coded. i can't use the set worksheet as ... because if it doesn't exist then the whole thing won't work

thanks
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
You could put this outside of your macro:

Rich (BB code):
Function SheetExists(ByVal wsName As String) As Boolean
    On Error Resume Next
    SheetExists = (Len(Sheets(wsName).Name) > 0)
  [FONT=&quot]End Function[/FONT]

and then put this inside your macro:

Rich (BB code):
if sheetexists("workingdata") then sheets("workingdata").delete
 
Upvote 0
Why test first?
Code:
On Error Resume Next
    Application.DisplayAlerts = False
    Sheets("WorkingData").Delete
    Application.DisplayAlerts = True
On Error Goto 0
 
Upvote 0

Forum statistics

Threads
1,215,734
Messages
6,126,543
Members
449,316
Latest member
sravya

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