ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Macro to delete charts (https://www.excelbanter.com/excel-programming/286678-macro-delete-charts.html)

bambam77[_5_]

Macro to delete charts
 
Is it possible to create a macro that can select and delete all of the
charts in a workbook. Regardless of their names?


---
Message posted from http://www.ExcelForum.com/


Debra Dalgleish

Macro to delete charts
 
This will remove chart sheets and embedded charts:

'====================================
Sub ChartsDelete()
Dim ch As Chart
Dim ws As Worksheet
Dim chObj As ChartObject
Application.DisplayAlerts = False

For Each ch In ActiveWorkbook.Charts
ch.Delete
Next

For Each ws In ActiveWorkbook.Worksheets
For Each chObj In ws.ChartObjects
chObj.Delete
Next
Next

Application.DisplayAlerts = True
End Sub
'==================================

bambam77 wrote:
Is it possible to create a macro that can select and delete all of the
charts in a workbook. Regardless of their names?


--
Debra Dalgleish
Excel FAQ, Tips & Book List
http://www.contextures.com/tiptech.html


bambam77[_6_]

Macro to delete charts
 
Thank you, this worked great. I have another question. I am new to thi
macro writing and I have done a few projects so far that have worked.

I have never used the Dim command, yet I see this a lot from peopl
here and in the delete chart code I just received. What is this Dim
And what does it do and when do I need it?

I know it has something to do with defining variables. I have used som
variables in some of my macros without the Dim command and they worke
fine so I'm kind of confused as to it's use.


Thank

--
Message posted from http://www.ExcelForum.com


Hotbird[_2_]

Macro to delete charts
 
Good Practice is to start your code with

OPTION EXPLICIT

then you will need to define variables with the DIM statement, but avoid
problems with duplicate names etc


"bambam77 " wrote in message
...
Thank you, this worked great. I have another question. I am new to this
macro writing and I have done a few projects so far that have worked.

I have never used the Dim command, yet I see this a lot from people
here and in the delete chart code I just received. What is this Dim?
And what does it do and when do I need it?

I know it has something to do with defining variables. I have used some
variables in some of my macros without the Dim command and they worked
fine so I'm kind of confused as to it's use.


Thanks


---
Message posted from http://www.ExcelForum.com/




Dave Peterson[_3_]

Macro to delete charts
 
And if you use "option explicit" and dim your variables appropriately, then you
can get the VBE's intellisense to pop up for you. (Less wear and tear on the
memory!)

Try this in a test module:

Option explicit
sub testme()
Dim Wks as worksheet
'now type wks. (as soon as you hit that dot, you should see some valid choices
for what you can do to a worksheet (or a property of the worksheet that you can
examine).

This is very nice to us older folks.

And by forcing you to declare your variables, you don't have to spend hours
looking for the mistake in this code:

for xlctr = 1 to 5
msgbox x1ctr
next xlctr

(the one's and ell's are mixed up).

You would have gotten an error when you tried to compile.

And this is nice to us older folks with bifocals!


"bambam77 <" wrote:

Thank you, this worked great. I have another question. I am new to this
macro writing and I have done a few projects so far that have worked.

I have never used the Dim command, yet I see this a lot from people
here and in the delete chart code I just received. What is this Dim?
And what does it do and when do I need it?

I know it has something to do with defining variables. I have used some
variables in some of my macros without the Dim command and they worked
fine so I'm kind of confused as to it's use.

Thanks

---
Message posted from http://www.ExcelForum.com/


--

Dave Peterson



All times are GMT +1. The time now is 11:15 AM.

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