Excel VBA chart looping

help_for_excel

Board Regular
Joined
Feb 24, 2012
Messages
72
Hi,

I want to write macro which goes through each of the chart and delete everything on it. each text box, each hyper link, each header, each tag on x axis and y axis.

I should just remain with blank chart window and nothing on it....


can any one please help.....thanks in advance (probably have to loop through each chart and delete each shapes etc)
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
<o:p> </o:p>
Please test the macro below.<o:p></o:p>
Do you have any text boxes or shapes outside the charts that you want to keep? Currently my code deletes them all, but it can be changed.<o:p></o:p>


Code:
Option Explicit
Sub Eraser()
Dim c As Chart, ax As Axis, s As Series
Dim i%, j%, ws As Worksheet
Set ws = ThisWorkbook.Worksheets(1)
For i = ws.OLEObjects.Count To 1 Step -1    ' every textbox in sheet
    If InStr(ws.OLEObjects(i).Name, "TextBox") Then ws.OLEObjects(i).Delete
Next
    
For i = ws.Shapes.Count To 1 Step -1    ' every shape except the charts
    If ws.Shapes(i).Type <> msoChart Then ws.Shapes(i).Delete
Next
For j = 1 To ws.ChartObjects.Count
    Set c = ws.ChartObjects(j).Chart
    For Each ax In c.Axes
        ax.Delete
    Next
    For Each s In c.SeriesCollection
        s.Delete
    Next
Next
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,781
Messages
6,132,672
Members
449,746
Latest member
signuptoignore

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