Adding and deleting worksheets

  • Thread starter Thread starter ChuckM
  • Start date Start date
C

ChuckM

I have 2 questions:
1. How can I add a worksheet to a workbook with a name that I specify?

2. How can I test for the existance of a worksheet by name...and then
delete it if I find it?

Thanks
chuck
 
You need to use VBA. Here's some code that will do what you want:

''
***************************************************************************
'' Purpose : Delete a named worksheet
''
Sub WorksheetDelete(wsName)
Dim ws
Dim lb_Ada As Boolean

For Each ws In Worksheets
If UCase(ws.Name) = UCase(wsName) Then
lb_Ada = Application.DisplayAlerts ''Remember setting
Application.DisplayAlerts = False ''Stop alerts
Worksheets(wsName).Delete ''Delete named worksheet
Application.DisplayAlerts = lb_Ada ''Reinstate setting
End If
Next

End Sub

--
Regards
Andy Wiggins
www.BygSoftware.com
Home of "Save and BackUp",
"The Excel Auditor" and "Byg Tools for VBA"
 
Back
Top