Adding and deleting worksheets

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
 
A

Andy Wiggins

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top