auto detect deletion

MR3

Board Regular
Joined
Jun 10, 2008
Messages
175
my code looks for currently existing worksheets.

for example....

Sheets("Name").Delete
Sheets("Address").Delete
Sheets("Telephone #").Delete

if it does not detect these sheets the code errors out.
if it does it proceeds and completes the code as written. If I want to run the code I always have to comment out and uncomment that specific block of code.

should i use a case statement? or an if statement so that if it finds them it delete else it jumps out and continues?
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Try this

Code:
If WorksheetExists("Name") Then Sheets("Name").Delete
If WorksheetExists("Address") Then Sheets("Address").Delete
If WorksheetExists("Telephone #") Then Sheets("Telephone #").Delete



Function WorksheetExists(WSName As String) As Boolean
On Error Resume Next
WorksheetExists = Worksheets(WSName).Name = WSName
On Error GoTo 0
End Function
 
Upvote 0
hi VoG,

i am not exactly sure where to insert the "Function" code. Should i put it above or below the if / then statements?

thanks
 
Upvote 0

Forum statistics

Threads
1,224,584
Messages
6,179,691
Members
452,938
Latest member
babeneker

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