Delete sheets on exit

  • Thread starter Thread starter tanyhart
  • Start date Start date
T

tanyhart

I have a macro that will create data sheets based upon the mai
worksheets information.

What I was wondering is, upon exiting the file, can I have excel delet
those created sheets so that when the file is opened again the macro ca
be run and new data presented?

Thank
 
To delete a sheet try this:

'Turn off user prompt
Application.DisplayAlerts = False

'Assuming the worksheet you want to delete is called data
Sheets("data").Delete

'Turn back on user prompt
Application.DisplayAlerts = True

Hope this helps

B
 
Hi Tanyhart,

Rather than deleting and recreating the sheets, why not delete the data,
e.g.:

'=============>>
Private Sub Workbook_Open()
Dim SH As Worksheet

For Each SH In Me.Worksheets
If UCase(Trim(SH.Name)) <> "MAIN" Then '<<==== CHANGE
SH.Cells.Clear
End If
Next SH

End Sub
'<<=============

This is workbook event code and should be pasted into the workbook's
ThisWorkbook module *not* a standard module or a sheet module:

Right-click the Excel icon on the worksheet
(or the icon to the left of the File menu if your workbook is maximised)
Select 'View Code' from the menu and paste the code.
Alt-F11 to return to Excel.
 

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

Back
Top