However this line 20 makes a bug for me: iSource = xChart.SeriesCollection.Count
I would appreciate your help!
Supposing there are multiple different types of charts in your worksheet, you have formatted one chart to your need, and now you want to apply this chart formatting to other charts. Of course, you can format others manually one by one, but this will waste much time, are there any quick or handy ways for you to copy one chart format to others in Excel?
Office Tab: Bring powerful tabs to Office (include Excel), just like Chrome, Safari, Firefox and Internet Explorer. Save you half the time, and reduce thousands of mouse clicks for you. 30-day Unlimited Free Trial
Kutools for Excel: Save 71% of your time and solve 82% Excel problems for you. 300+ advanced tools designed for 1500+ work scenario, make Excel much easy and increase productivity immediately.60-day Unlimited Free Trial
Please look at the following screenshot, the first chart has the formatting which you need, and now, you want to apply its formatting to other charts.
This Paste Special function can help you to copy one chart format to other charts with following steps:
1. Select the chart that you want to copy its format to others.
2. Then on the Home tab, click Copy, see screenshot:
3. And then select another chart that you want to reformat, then click Home > Paste > Paste Special, and in the popped out dialog, check Formats under Paste option. See screenshots:
4. Then click OK, and the chart formatting has been applied to this chart, and then repeat this procedure for each chart you want to reformat. At last you will get the following results:
You can also save your formatted chart as a chart template, and then change other charts type to your template chart type.
1. Select your needed formatting chart, on the Design tab, click Save As Template, see screenshot:
2. In the Save Chart Template window, specify a name for your template chart, and then click Save. And it will be saved with the rest of the chart types, in a Templates folder, it can be chosen when you create a new chart.
3. After creating your template chart, then you can change other chart types to this template, select the chart which needed to be reformatting and right click, choose Change Chart Type from the context menu, see screenshot:
4. In the Change Chart Type dialog, click Templates from the left pane, and select your created chart template under My Templates option.
5. Then click OK to close this dialog, and the chart's formatting has been copied to this selected chart. See screenshot:
6. Then repeat the above step 3- step5 to copy the format to other charts one by one.
With above two methods, you must paste or change the chart's formatting one by one, if there are multiple charts need to be reformatted, the following VBA code can help you apply one chart format to others at once in the current worksheet.
1. Select the chart that you want to apply its format to other charts.
2. Hold down the ALT + F11 keys to open the Microsoft Visual Basic for Applications Window.
3. Click Insert > Module, and paste the following macro in the Module Window:
VBA code: Copy one chart format to other chart at once
Sub CopyChartFormats() 'Updateby20140219 Dim Ws As Worksheet Dim Cht As ChartObject Dim xChart As Chart Dim bTitle As Boolean Dim bXTitle As Boolean Dim bYTitle As Boolean Dim sTitle As String Dim sXTitle As String Dim sYTitle As String Dim iSource As Long Dim iTarget As Long Dim iTotal As Long Dim iSeries As Long Dim vSource As Variant Dim vTarget As Variant Application.ScreenUpdating = False Set xChart = Application.ActiveChart iSource = xChart.SeriesCollection.Count Set Ws = Application.ActiveSheet For Each Cht In Ws.ChartObjects If Ws.Name = xChart.Parent.Parent.Name And _ Cht.Name = xChart.Parent.Name Then Else With Cht.Chart iTarget = .SeriesCollection.Count bTitle = .HasTitle If bTitle Then sTitle = .ChartTitle.Characters.Text End If If .HasAxis(xlCategory) Then bXTitle = .Axes(xlCategory).HasTitle If bXTitle Then sXTitle = .Axes(xlCategory).AxisTitle.Characters.Text End If End If If .HasAxis(xlValue) Then bYTitle = .Axes(xlValue).HasTitle If bYTitle Then sYTitle = .Axes(xlValue).AxisTitle.Characters.Text End If End If xChart.ChartArea.Copy .Paste Type:=xlFormats iTotal = .SeriesCollection.Count If iTotal = iSource + iTarget Then For iSeries = 1 To iTarget vSource = Split(.SeriesCollection(iSeries).Formula, ",") vTarget = Split(.SeriesCollection(iSeries + iSource).Formula, ",") vTarget(UBound(vTarget)) = vSource(UBound(vSource)) .SeriesCollection(iSeries).Formula = Join(vTarget, ",") Next For iSeries = iTotal To iTarget + 1 Step -1 .SeriesCollection(iSeries).Delete Next End If If bXTitle Then .Axes(xlCategory).HasTitle = True .Axes(xlCategory).AxisTitle.Characters.Text = sXTitle End If If bYTitle Then .Axes(xlValue).HasTitle = True .Axes(xlValue).AxisTitle.Characters.Text = sYTitle End If If bTitle Then .HasTitle = True .ChartTitle.Characters.Text = sTitle End If End With End If Next Application.ScreenUpdating = True End Sub
4. Then press F5 key to run this code, and all other charts in current worksheet are applied with the formatting of the selected chart immediately.