XLA routines: EE_DeleteSheet
Deleting a sheet using VBA is more work than it should be. Here's a routine that accepts either a sheet name as string or a worksheet.
Sub EE_DeleteSheet(sht As Variant) Dim blnDisplayAlerts As Boolean Dim wks As Object Dim wbk As Workbook ' http://excelexperts.com/xla-routines-eedeletesheet Set wbk = ActiveWorkbook On Error Resume Next Select Case TypeName(sht) Case "String" Set wks = wbk.Worksheets(CStr(sht)) Case "Worksheet", "Sheet" Set wks = sht End Select Err.Clear: On Error GoTo 0: On Error GoTo -1 blnDisplayAlerts = Application.DisplayAlerts Application.DisplayAlerts = False If Not wks Is Nothing Then wks.Delete End If Application.DisplayAlerts = blnDisplayAlerts Set wks = Nothing Set wbk = Nothing End Sub
»
- Nick's blog
- Login or register to post comments
- 2780 reads
Recent comments
5 years 36 weeks ago
6 years 22 weeks ago
6 years 34 weeks ago
6 years 37 weeks ago
6 years 38 weeks ago
6 years 43 weeks ago
6 years 52 weeks ago
7 years 2 days ago
7 years 3 days ago
7 years 3 days ago