To delete the worksheet which already exist you may try the below code.
If there are many sheets to delete , i recommend using separate procedure as shown below and then use the call function whenever needed.
Lets assume we need to delete tab name "Temp" and "Calculations", then you may use the below code.
Sub Main_Macro()
Call DeleteSheet("Temp")
Call DeleteSheet("Calculations")
End Sub
Private Sub DeleteSheet(ShtName As String)
Dim Ws As Worksheet
For Each Ws In ActiveWorkbook.Sheets
If UCase(Ws.Name) = UCase(ShtName) Then
Ws.Delete
Exit For
End If
Next Ws
End Sub
No comments:
Post a Comment