Auto Answer Prompt

Bench

Board Regular
Joined
Aug 27, 2009
Messages
134
Hi,

I've written a code that creates several charts in one go, first though it checks whether these already exist, if they do it deletes them.

This works fine, however at each sheet i have to confirm deletion via the microsoft prompt:

"Data May Exist in the Sheet(s) selected for Deletion. To Permanently delete the Data press Delete: Delete/Cancel"

Is there a bit of code i can add, to automatically choose Delete and stop it pausing the Sub ???

Please Help

Thanks
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Use:
Code:
 Application.DisplayAlerts = False
' code to delete
 Application.DisplayAlerts = True
to automatically select the default response.
 
Upvote 0
Use:
Code:
 Application.DisplayAlerts = False
' code to delete
 Application.DisplayAlerts = True
to automatically select the default response.

Hey, Thanks for the speedy reply, its not working although i imagine that may be because i've put it in the wrong place. I tried right at the start of the code and as below. Where should it go? Thanks

Code:
For Each chart_name In ThisWorkbook.Charts
If chart_name.Name = "2.Completed Cases YTD" Then
chart_name.Delete
Application.DisplayAlerts = True
End If

Next
 
Upvote 0
That should be fine assuming you are only deleting one chart, and assuming this is all one procedure. Are you still getting the prompt?
 
Upvote 0
That should be fine assuming you are only deleting one chart, and assuming this is all one procedure. Are you still getting the prompt?

It's ok, i've realised my error, should be

Code:
For Each chart_name In ThisWorkbook.Charts
If chart_name.Name = "2.Completed Cases YTD" Then
Application.DisplayAlerts = False
chart_name.Delete
Application.DisplayAlerts = True
End If
Next

I was missing out the False bit, thanks for your help
 
Upvote 0

Forum statistics

Threads
1,215,473
Messages
6,125,018
Members
449,203
Latest member
tungnmqn90

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top