I disagree that the "most straightforward" approach is to intentionally generate (and suppress) an error. Personally I'd opt for the loop-to-locate method, only attempting deletion if the object exists.
If you're going to be re-creating the worksheet anyway, this will do the job in almost every case:
Sheets("asdf").Cells.Delete 'deletes all cells in the specified worksheet
Safely Delete a Worksheet
If the one-liner (above) doesn't work for you (maybe due to some stubborn background colors/images) then here's a sub that you can call to delete any specified worksheet:
Sub deleteSheet(wsName As String)
Dim ws As Worksheet
For Each ws In ThisWorkbook.Sheets 'loop to find sheet (if it exists)
Application.DisplayAlerts = False 'hide confirmation from user
If ws.Name = wsName Then ws.Delete 'found it! - delete it
Application.DisplayAlerts = True 'show future confirmations
Next ws
End Sub
Call it simply like:
deleteSheet "asdf"
...where asdf
is the name of the worksheet (tab) to delete.
Delete & Replace a Worksheet
Alternatively, calling the sub below will delete and replace the worksheet, giving it the same name and putting it in the same tab position as the original:
Sub resetSheet(wsName As String)
Dim ws As Worksheet, ws2 As Worksheet
For Each ws In ThisWorkbook.Sheets 'loop to find sheet (if it exists)
If ws.Name = wsName Then 'found it!
Set ws2 = ThisWorkbook.Sheets.Add(ws) 'add new sheet located before old one
Application.DisplayAlerts = False 'hide confirmation from user
ws.Delete 'delete sheet (new one takes its place)
Application.DisplayAlerts = True 'show future confirmations
ws2.Name = wsName 'rename new sheet to old name
Exit Sub 'finished! (no need to continue looping)
End If
Next ws
End Sub
I used ThisWorkbook
in both subs, which is important when running VBA that modifies other workbooks, or while you have multiple workbooks open at the same time.
Using ThisWorkbook
ensures that your code is always referring to the workbook where the code is located that called it.
Without it, for example, if you have two similar files open, and you're looking at one while you're waiting for VBA to run in the other workbook, if the workbook that's "on top" has a worksheet with the name of the one VBA's trying to delete, it will delete the worksheet in the current (active) workbook instead of the intended one.
(...and you can't Ctrl+Z to undo VBA!)