Macro Delete Sheet

  • Thread starter Thread starter Stephen
  • Start date Start date
S

Stephen

Hi

Within a macro I want to delete a certain sheet. What is the best wa
to do that?

Stephe
 
Hi
try
Application.displayalerts = false
worksheets("sheetname").delete
Application.displayalerts = True
 
What if you wanted a macro to look thru the workbook and delete all th
sheets named Chart*? How would you get a macro to look through th
whole workbook
 
One way.

Option Explicit
Sub testme02()

Dim mySheet As Object

Application.DisplayAlerts = False
On Error Resume Next

For Each mySheet In ActiveWorkbook.Sheets
If LCase(mySheet.Name) Like "chart*" Then
mySheet.Delete
End If
Next mySheet

On Error GoTo 0
Application.DisplayAlerts = True

End Sub

The ".displayalerts = false" stops the "are you sure" prompts.

The "on error" stuff prevents an error if you try to delete the only visible
sheet remaining. (There always has to be at least one visible sheet in your
workbook.)
 
Back
Top