if statement to delete sheets

Dummy Excel

Well-known Member
Joined
Sep 21, 2005
Messages
1,004
Office Version
  1. 2019
  2. 2010
  3. 2007
Platform
  1. Windows
Hi Guys,
I need to write some code so that if a worksheet is there ie DATA, then the macro removes that worksheet.

any help would be greatly appreciated
thanks
Sam
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
try:
Code:
For Each ws In ThisWorkbook.Worksheets
     If ws.Name = "DATA" Then
        Application.DisplayAlerts = False
        ws.Delete
        Application.DisplayAlerts = True
    End If
Next ws
 
Upvote 0
when I run this, it looks like it does something, however it doesnt delete the worksheet
 
Upvote 0
Code:
On Error Resume Next
Application.DesplayAlerts = False
Sheets("Data").Delete
Application.DisplayAlerts = True
End Sub

It will not delete the sheet if it is the only sheet in the workbook.
 
Upvote 0
sorry it does work - i just relised that it is case sensitive.
Is there anyway that we can make it so that it is not case sensitive?

thanks
 
Upvote 0

Forum statistics

Threads
1,214,652
Messages
6,120,747
Members
448,989
Latest member
mariah3

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