Sub example_1()
On Error Resume Next
'Sheets("Sheet8").Activate
'or
With Sheets("Sheet8"): End With
If Err Then Sheets.Add(after:=Sheets(Sheets.Count)).Name = "Sheet8": Err.Clear
On Error GoTo 0
End Sub
Sub example_2()
Dim wsh As Worksheet, bu As Boolean: bu = True
For Each wsh In ThisWorkbook.Worksheets
If wsh.Name = "Sheet8" Then bu = False: Exit For
Next wsh
If bu Then Sheets.Add(after:=Sheets(Sheets.Count)).Name = "Sheet8"
End Sub
Sub example_3()
Dim s$: s = "Sheet8"
If Not Evaluate("ISREF('" & s & "'!A1)") Then
Sheets.Add(after:=Sheets(Sheets.Count)).Name = s
Else
Sheets(s).Activate
End If
End Sub
Sub example_4()
If SheetExists("Sheet8") = False Then
Sheets.Add after:=Worksheets(Worksheets.Count)
ActiveSheet.Name = "Sheet8"
End If
End Sub
Function SheetExists(WSName) As Boolean
On Error Resume Next
SheetExists = Sheets(WSName).Name = WSName
On Error GoTo 0
End Function
|