XLA Routines: EE_ReplaceSheet
EE_ReplaceSheet is a useful routine that replaces a sheet, and does not error if the sheet does not exist meaning you can use the routine to create a new sheet.
Function EE_ReplaceSheet(strSheet As String) As Worksheet Dim wksNew As Worksheet Dim wbk As Workbook Dim blnDisplayAlerts As Boolean Set wbk = ActiveWorkbook On Error Resume Next Set wksNew = wbk.Worksheets.Add(after:=wbk.Worksheets(strSheet)) Err.Clear: On Error GoTo 0: On Error GoTo -1 If wksNew Is Nothing Then Set wksNew = wbk.Worksheets.Add(after:=wbk.Worksheets(ThisWorkbook.Worksheets.Count)) wksNew.Name = strSheet Set wksNew = Nothing Exit Function End If blnDisplayAlerts = Application.DisplayAlerts Application.DisplayAlerts = False On Error Resume Next wbk.Worksheets(strSheet).Delete wksNew.Name = strSheet Err.Clear: On Error GoTo 0: On Error GoTo -1 Application.DisplayAlerts = blnDisplayAlerts Set EE_ReplaceSheet = wksNew Set wksNew = Nothing Set wbk = Nothing End Function
»
- Nick's blog
- Login or register to post comments
- 2686 reads
Recent comments
5 years 41 weeks ago
6 years 27 weeks ago
6 years 39 weeks ago
6 years 42 weeks ago
6 years 43 weeks ago
6 years 48 weeks ago
7 years 4 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago
7 years 5 weeks ago