deleteing charts using "wildcard"

  • Thread starter Thread starter RogerDaShrubber
  • Start date Start date
R

RogerDaShrubber

I am trying to write a macro that will go thru a workbook and delete al
charts whose title starts with the word "chart". Does anyone know ho
to do this. Thank you for your hel
 
Hi Roger,
I am trying to write a macro that will go thru a workbook and delete all
charts whose title starts with the word "chart". Does anyone know how
to do this. Thank you for your help

When you say 'title', do you mean the name of the chart sheet tab, or the
text of the chart title? If the latter, are the charts embedded in
worksheets, or just on their own sheets?

Regards

Stephen Bullen
Microsoft MVP - Excel
www.BMSLtd.ie
 
Roger,

I don't know how to cycle through all the sheets in a workbook but th
code below looks at all the charts on a sheet and if the title start
with the word "Chart" it deletes that chart.

I'm sure there must be another loop which goes through all the sheet
in the workbook.

Hope this helps

Sub Delete_Chart()

Dim Cht As ChartObject

For Each Cht In ActiveSheet.ChartObjects
If Left(Cht.Name, 5) = "Chart" Then
Cht.Delete
End If
Next

End Sub

Regards

Seamu
 
Seamus
Thank you. Thanks half of the puzzle. Maybe I can figure out th
rest myself. Thanks again
 
SOS said:
*Roger,

I don't know how to cycle through all the sheets in a workbook but
the code below looks at all the charts on a sheet and if the title
starts with the word "Chart" it deletes that chart.

I'm sure there must be another loop which goes through all the sheets
in the workbook.

Hope this helps

Sub Delete_Chart()

Dim Cht As ChartObject

For Each Cht In ActiveSheet.ChartObjects
If Left(Cht.Name, 5) = "Chart" Then
Cht.Delete
End If
Next

End Sub

Regards

Seamus *

To make a little more general you can even say
For Each Cht In ActiveSheet.ChartObjects
If ucase(trim(Cht.Name)) like "CHART*" Then
Cht.Delete
End If
Next

takes care of any capitalization issues and leading spaces.

keith
www.kjtfs.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top