Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Delete Sheet in excel 2

Status
Not open for further replies.

mgp

Mechanical
Joined
May 30, 2001
Messages
224
Location
DK
I'm trying to write a code to copy a worksheet, do something and then delete it. Problem is I get this prompt before the sheet is deleted:

"Data may exist in the sheet(s) selected for deletion.To permanently delete the data, press delete."

How do I get my code to avoid that prompt or automatically accept it?

Sub Macro1()
Sheets("Template").Copy Before:=Sheets(1)
xxx
xxx
Sheets("Template (2)").Delete
End Sub


regards
Mogens
 
A very primitive workaround could be to create a new workbook with the copied sheet and then delete it.

Something like:

Sub Macro1()
Sheets("Template").Copy
With ActiveWorkbook.Sheets("Template")
'.Range("C3:E7").ClearContents
'xxx
'xxx
End With
ActiveWindow.Close (False)
End Sub


HTH

_LF
 
Hello mgp,

to avoid such prompts, try to insert the following command line just before your "delete"-command:

Application.DisplayAlerts = False

I hope it may help.

Good luck !

 
Thanks BurattoN

Works perfect

Regards
Mogens
 
And then put its converse just after your "delete" command, especially if your code is still under development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top