Hi,
I have a workbook I'm using to produce a set of reports. Each report has various sheets each with various charts.
I have a combo box, which allows me to select criteria for the report. This applies filters to hidden sheets, which makes my 'new' report. The new report is then saved to a new file.
I'm trying to clean up the charts as part of the process, by ensuring that the value axis is scaled in whole numbers only.
If I run the code as an external proc call within the Change event for the combo box, it doesn't work. (Note there is other stuff happening in the change event too, whereabouts in the action order I place the call has no effect).
If I attempt to just run the code itself within the change event, it runs once ok, then on the second run generates a "method Axes of object _Chart failed" error, and Excel then crashes if I try to make any action within the VBE (memory leak maybe?).
If I run it as a standalone proc after my Change event has cleared, it works just fine.
I have to run the operation off the combobox change event (or consecutively and seamlessly, without action from the end user).
Here's the code:
Any suggestions?
NB: Values per chart can range from 0 to 200, so it isn't possible to just set the MajorUnit to 1 for all circumstances.
Regards, Iain
I have a workbook I'm using to produce a set of reports. Each report has various sheets each with various charts.
I have a combo box, which allows me to select criteria for the report. This applies filters to hidden sheets, which makes my 'new' report. The new report is then saved to a new file.
I'm trying to clean up the charts as part of the process, by ensuring that the value axis is scaled in whole numbers only.
If I run the code as an external proc call within the Change event for the combo box, it doesn't work. (Note there is other stuff happening in the change event too, whereabouts in the action order I place the call has no effect).
If I attempt to just run the code itself within the change event, it runs once ok, then on the second run generates a "method Axes of object _Chart failed" error, and Excel then crashes if I try to make any action within the VBE (memory leak maybe?).
If I run it as a standalone proc after my Change event has cleared, it works just fine.
I have to run the operation off the combobox change event (or consecutively and seamlessly, without action from the end user).
Here's the code:
Code:
Dim s As Integer
Dim c As Integer
Dim chChart As Chart
Dim choChObj As ChartObject
Dim shtCurrent As Worksheet
For s = 1 To ActiveWorkbook.Worksheets.Count
Set shtCurrent = shtCurrent
Debug.Print shtCurrent.Name
shtCurrent.Activate
If shtCurrent.Visible = True And shtCurrent.ChartObjects.Count > 0 Then
'---------------------------------------------------------------
' check the charts in the sheet, if major unit < 1 then set to 1
'---------------------------------------------------------------
' loop through the ChartObjects on the sheet
For c = 1 To shtCurrent.ChartObjects.Count
' activate the ChartObject
'shtcurrent.ChartObjects(c).Activate
Debug.Print shtCurrent.ChartObjects(c).Chart.Name
' assign variables
Set choChObj = shtCurrent.ChartObjects(c)
Set chChart = choChObj.Chart
' reset the scales back to auto
chChart.Axes(xlValue).MajorUnitIsAuto = True
' is there now a decimal point in the MajorUnit?
If InStr(1, CStr(chChart.Axes(xlValue).MajorUnit), ".") <> 0 Then
'if so, reset the MajorUnit to the nearest integer
chChart.Axes(xlValue).MajorUnit = Application.WorksheetFunction.RoundUp(chChart.Axes(xlValue).MajorUnit, 0)
End If
Next c
End If
Next s
Worksheets("Tier 1 Dashboard").Select
Set chChart = Nothing
Set choChObj = Nothing
Set shtCurrent = Nothing
Any suggestions?
NB: Values per chart can range from 0 to 200, so it isn't possible to just set the MajorUnit to 1 for all circumstances.
Regards, Iain