Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Filtering Columns for Unique Values
Printing Multiple Worksheets on a Single Page
Chris has a workbook that contains a lot of small, identical charts. He wants to change some of the attributes of elements in each chart--such as color or font size--all at one time.
If you find yourself using a "non-default" chart often (which means changing the appearance of certain chart elements after the chart is created), then a great approach is to create a custom chart and save that format in Excel. You can then use the saved format to create all your new charts, thereby minimizing the amount of later formatting you need to do. How you save custom chart formats has been covered in other issues of ExcelTips.
Custom chart formats may be great for the future, but it doesn't help if you already have a whole bunch of charts in an existing workbook. In that case, the best solution is to use a macro which can step through all the charts in a workbook and make a desired change. You just need to decide up front which items you wish to change, and then program the macro to specifically change those items.
For example, the following macro changes the font color and size of the Y-axis labels. It loops through all the charts in the workbook, both sheets and embedded charts.
Sub ChangeAllCharts1()
Dim cht As Chart
Dim sht
Dim ChtObj As ChartObject
For Each cht In ActiveWorkbook.Charts
With cht.Axes(xlValue).TickLabels.Font
.Size = 20
.Color = vbRed
End With
Next
For Each sht In ActiveWorkbook.Sheets
For Each ChtObj In sht.ChartObjects
With ChtObj.Chart.Axes(xlValue).TickLabels.Font
.Size = 20
.Color = vbRed
End With
Next
Next
End Sub
As written here, the macro changes the font size to 20 and the color to red. If you want the macro to change other elements, all you need to do is change the With statements to reflect the elements you want changed, or you could use a For...Next loop to step through all the chart elements. The following macro exhibits this technique, changing the background color of the charts in a workbook.
Sub ChangeAllCharts2()
On Error Resume Next
NewChartAreaColor = 34
For J = 1 To ActiveWorkbook.Charts.Count
ActiveWorkbook.Charts(J).Select
'The pairs of line code indicate desired changes
ActiveChart.ChartArea.Select
Selection.Interior.ColorIndex = NewChartAreaColor
Next J
For J = 1 To ActiveWorkbook.Sheets.Count
For K = 1 To Sheets(J).ChartObjects.Count
Sheets(J).Select
Sheets(J).ChartObjects(K).Activate
'The pairs of line code indicate desired changes
ActiveChart.ChartArea.Select
Selection.Interior.ColorIndex = NewChartAreaColor
Next K
Next J
End Sub
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (3125) applies to Microsoft Excel versions: 97 2000 2002 2003
A Picture is Worth Thousands! Your worksheets are not limited to holding numbers and text. You can also add graphics or easily create charts based on your data. Excel Graphics and Charts, available in two versions, helps you make your graphics and charts their absolute best.