Created
August 9, 2011 12:45
-
-
Save ogra/1133946 to your computer and use it in GitHub Desktop.
Excel macro to make clustered charts' axes in the book start from zero.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sub FixChartAxes() | |
' | |
' FixChartAxes Macro | |
' | |
' Define chart types to process | |
Dim chart_types As New Collection | |
With chart_types | |
.Add Item:=xlBarClustered | |
.Add Item:=xlColumnClustered | |
.Add Item:=xl3DBarClustered | |
.Add Item:=xl3DColumnClustered | |
.Add Item:=xlConeBarClustered | |
.Add Item:=xlConeColClustered | |
.Add Item:=xlCylinderBarClustered | |
.Add Item:=xlCylinderColClustered | |
.Add Item:=xlPyramidBarClustered | |
.Add Item:=xlPyramidColClustered | |
End With | |
On Error GoTo noChartSheet | |
' MsgBox ("Number of chart sheets: " & ActiveWorkbook.Charts.Count) | |
For i = 1 To ActiveWorkbook.Charts.Count | |
With ActiveWorkbook.Charts(i) | |
For c = 1 To chart_types.Count | |
If .charttype = chart_types(c) Then | |
.Axes(xlValue).MinimumScale = 0 | |
End If | |
Next | |
End With | |
Next | |
On Error GoTo noEmbedChart | |
For i = 1 To ActiveWorkbook.Worksheets.Count | |
With ActiveWorkbook.Worksheets(i) | |
' MsgBox ("Worksheet name: " & .Name & ", Number of embedded charts: " & .ChartObjects.Count) | |
For j = 1 To .ChartObjects.Count | |
With .ChartObjects(j).Chart | |
For c = 1 To chart_types.Count | |
If .charttype = chart_types(c) Then | |
.Axes(xlValue).MinimumScale = 0 | |
End If | |
Next | |
End With | |
Next | |
End With | |
Next | |
Exit Sub | |
noChartSheet: | |
' MsgBox "There is no chart sheet in this book." | |
noEmbedChart: | |
' MsgBox "There is no embedded chart in this worksheet." | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment