Microsoft Office Tutorials and References
In Depth Information
Deleting Charts
‘Continue and close the loop for every chart on that sheet.
Next ChObj
‘Close the If structure if the worksheet had no chart.
End If
‘Continue and close the loop for every worksheet.
Next wks
‘Turn on ScreenUpdating.
Application.ScreenUpdating = True
End Sub
If you have chart sheets to be looped through, the code must be different to take into account the
type of sheet to look for, because a chart sheet is a different type of sheet than a worksheet. This
macro accomplishes the same task of coloring the chart area, but for charts on chart sheets:
Sub LoopAllChartSheets()
‘Turn off ScreenUpdating.
Application.ScreenUpdating = False
‘Declare an object variable for the Sheets collection.
Dim objSheet As Object
‘Loop through all sheets, only looking for a chart sheet.
For Each objSheet In ActiveWorkbook.Sheets
If TypeOf objSheet Is Excel.Chart Then
‘Activate the chart sheet.
‘Color the chart area blue.
ActiveChart.ChartArea.Interior.ColorIndex = 8
‘Close the If structure and move on to the next sheet.
End If
Next objSheet
‘Turn on ScreenUpdating.
Application.ScreenUpdating = True
End Sub
dElETing cHArTs
To delete all charts on a worksheet, you can execute this code line in the Immediate Window, or as
part of a macro:
If activesheet.ChartObjects.Count > 0 Then activesheet.ChartObjects.Delete
Search JabSto ::

Custom Search