×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Delete Sheet in excel
2

Delete Sheet in excel

Delete Sheet in excel

(OP)
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

RE: Delete Sheet in excel

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

RE: Delete Sheet in excel

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 !

RE: Delete Sheet in excel

(OP)
Thanks BurattoN

Works perfect

Regards
Mogens

RE: Delete Sheet in excel

And then put its converse just after your "delete" command, especially if your code is still under development.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources