ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Delete sheets on exit (https://www.excelbanter.com/excel-programming/365114-delete-sheets-exit.html)

tanyhart[_27_]

Delete sheets on exit
 

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

--
tanyhar
-----------------------------------------------------------------------
tanyhart's Profile: http://www.excelforum.com/member.php...fo&userid=3514
View this thread: http://www.excelforum.com/showthread.php?threadid=55467


ben77[_3_]

Delete sheets on exit
 

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

tanyhart Wrote:
I have a macro that will create data sheets based upon the main
worksheets information.

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

Thanks



--
ben77
------------------------------------------------------------------------
ben77's Profile: http://www.excelforum.com/member.php...o&userid=35602
View this thread: http://www.excelforum.com/showthread...hreadid=554671


Norman Jones

Delete sheets on exit
 
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.


---
Regards,
Norman


"tanyhart" wrote in
message ...

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

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

Thanks


--
tanyhart
------------------------------------------------------------------------
tanyhart's Profile:
http://www.excelforum.com/member.php...o&userid=35148
View this thread: http://www.excelforum.com/showthread...hreadid=554671





All times are GMT +1. The time now is 06:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com