By using listi.net you agree to our cookie policy, We and our partners operate globally and use cookies, for multiple purposes
listi.net
CreateSheet - Creates a new sheet in the active workbook
Function CreateSheet(sh As String) 'Version: 1.001 'Purpose: To Create a sheet for passed name and delete the sheet if it already exists On Error Resume Next CreateSheet = "" Worksheets(sh).Visible = True On Error Resume Next Worksheets(sh).Select If Err = 9 Or Err = -2147352565 Then 'nothing to do sheet doesn't exist ElseIf Err = 0 Then 'Delete the sheet Application.DisplayAlerts = False
ActiveWindow.SelectedSheets.Delete '@ this is worrysome Application.DisplayAlerts = True Else CreateSheet = "Unexpected error during CreateSheet = " & Err & " " & Error
End If On Error Resume Next
Sheets.Add.Name = sh If ActiveSheet.Name <> sh Then 'There may be a problem with Excel CreateSheet = "Excel is behaving Strangely. Added sheet but not added. Usually due to resource issue" Exit Function End If