Logo 
Search:

MS Office Forum

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds

Changing Chart attributes without activating the sheet/chart

  Asked By: Lewis    Date: Jan 30    Category: MS Office    Views: 1235
  

I have code that changes the attributes of a series of charts on a
number of different sheets. The code run slowly and I am suspecting
that it is because I am activating each sheet and chart to make the
necessary attribute changes. Is there a way to change chart
attributes without activating the chart and or sheet?

Public Sub OneAxis_BodyExpCharts()

Dim Chart1 As Object

On Error Resume Next

If ActiveSheet.Name = SHEET_BODY_EXP Then
For Each Chart1 In Sheets(SHEET_BODY_EXP).ChartObjects
Chart1.Activate
If ActiveChart.SeriesCollection(2).AxisGroup = 2 Then
ActiveChart.SeriesCollection(2).Select
Selection.AxisGroup = 1
Selection.ChartType = xlColumnClustered
End If
Next
End If

End Sub

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Bin Fischer     Answered On: Jan 30

The following code  hasn't been tested, but you shouldget the drift.

Public Sub OneAxis_BodyExpCharts()

Dim Chart1 As Object

On Error Resume Next

If ActiveSheet.Name = SHEET_BODY_EXP Then
For Each Chart1 In Sheets(SHEET_BODY_EXP).ChartObjects
If Chart1.SeriesCollection(2).AxisGroup = 2 Then
With Chart1.SeriesCollection(2)
.AxisGroup = 1
.ChartType = xlColumnClustered
End With
End If
Next Chart1
End If

End Sub