excel vba delete worksheet if exists 1

excel vba delete worksheet if exists

For Each ws In Worksheets
    If ws.Name = "asdf" Then
        Application.DisplayAlerts = False
        Sheets("asdf").Delete
        Application.DisplayAlerts = True
    End If
Next

Sheets.Add(After:=Sheets(Sheets.count)).Name = "asdf"

Here is what the above code is Doing:
1. It’s looping through all the worksheets in the workbook.
2. If the worksheet name is “asdf”, it deletes it.
3. It adds a new worksheet named “asdf”.

Similar Posts