Excel VBA




About Us

Create A New Sheet

'******************************************************************** ' http://www.KravatzInc.com 1-866-XLS-PROG ' ' This code is copyrighted by Kravatz, Inc. (c) 2007 All Rights Reserved. ' You may use this code as long as this message appears ' There is no warranty made to the fitness or suitablilty of this code ' and by using it you hold Kravatz, Inc. harmless for any damages ' that may result from its use. This code is supplied as is. ' '******************************************************************** Sub CreateSheet(sh As String) On Error Resume Next 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 MsgBox "Unexpected error during CreateSheet = " & Err & " " & Error End If On Error GoTo 0 Sheets.Add.Name = sh Sheets(sh).Move After:=Sheets(Sheets.Count) End Sub