Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 25
Default Auto Scaling Charts

I am trying (in Vain) to auto scale bar charts in excel. I have attempted a
macro in VB to do this, but it just seems to do nothing, does not fail or
succeeds. If anyone could take a look at the macro below and assist in where
it is going wrong would be much appreciated.
Thanks

Sub AutoScaleCharts()

Dim ws As Worksheet
Dim cht As ChartObject
Dim ValuesArray(), SeriesValues As Variant
Dim Ctr As Integer, TotCtr As Integer

For Each ws In ThisWorkbook.Worksheets
For Each cht In ws.ChartObjects
For Each X In cht.Chart.SeriesCollection
SeriesValues = X.Values
ReDim Preserve ValuesArray(1 To TotCtr + UBound(SeriesValues))
For Ctr = 1 To UBound(SeriesValues)
ValuesArray(Ctr + TotCtr) = SeriesValues(Ctr)
Next
TotCtr = TotCtr + UBound(SeriesValues)
Next X
' Reset the minimum and maximum scale to the minimum and
' maximum values in the ValuesArray.
If cht.Chart.HasAxis(xlValue, xlPrimary) Then
cht.Chart.Axes(xlValue, xlPrimary).MinimumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlPrimary).MaximumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlPrimary).MinimumScale =
Application.Min(ValuesArray)
cht.Chart.Axes(xlValue, xlPrimary).MaximumScale =
Application.Max(ValuesArray)
ElseIf cht.Chart.HasAxis(xlValue, xlSecondary) Then
cht.Chart.Axes(xlValue, xlSecondary).MinimumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlSecondary).MaximumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlSecondary).MinimumScale =
Application.Min(ValuesArray)
cht.Chart.Axes(xlValue, xlSecondary).MaximumScale =
Application.Max(ValuesArray)
End If
Next cht
Next ws

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 2,489
Default Auto Scaling Charts

Hi,

Setting the value turns off the Auto scaling on the axis.

So in your code,

' autoscaling ON
cht.Chart.Axes(xlValue, xlPrimary).MinimumScaleIsAuto = True
' autoscaling OFF
cht.Chart.Axes(xlValue, xlPrimary).MinimumScale =
Application.Min(ValuesArray)

Cheers
Andy

--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"gibsol" wrote in message
...
I am trying (in Vain) to auto scale bar charts in excel. I have attempted a
macro in VB to do this, but it just seems to do nothing, does not fail or
succeeds. If anyone could take a look at the macro below and assist in
where
it is going wrong would be much appreciated.
Thanks

Sub AutoScaleCharts()

Dim ws As Worksheet
Dim cht As ChartObject
Dim ValuesArray(), SeriesValues As Variant
Dim Ctr As Integer, TotCtr As Integer

For Each ws In ThisWorkbook.Worksheets
For Each cht In ws.ChartObjects
For Each X In cht.Chart.SeriesCollection
SeriesValues = X.Values
ReDim Preserve ValuesArray(1 To TotCtr + UBound(SeriesValues))
For Ctr = 1 To UBound(SeriesValues)
ValuesArray(Ctr + TotCtr) = SeriesValues(Ctr)
Next
TotCtr = TotCtr + UBound(SeriesValues)
Next X
' Reset the minimum and maximum scale to the minimum and
' maximum values in the ValuesArray.
If cht.Chart.HasAxis(xlValue, xlPrimary) Then
cht.Chart.Axes(xlValue, xlPrimary).MinimumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlPrimary).MaximumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlPrimary).MinimumScale =
Application.Min(ValuesArray)
cht.Chart.Axes(xlValue, xlPrimary).MaximumScale =
Application.Max(ValuesArray)
ElseIf cht.Chart.HasAxis(xlValue, xlSecondary) Then
cht.Chart.Axes(xlValue, xlSecondary).MinimumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlSecondary).MaximumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlSecondary).MinimumScale =
Application.Min(ValuesArray)
cht.Chart.Axes(xlValue, xlSecondary).MaximumScale =
Application.Max(ValuesArray)
End If
Next cht
Next ws

End Sub


  #3   Report Post  
Posted to microsoft.public.excel.charting
external usenet poster
 
Posts: 6,582
Default Auto Scaling Charts

Clarification:

Are you trying to autoscale chart axes, that is, let Excel apply the scale
based on its internal algorithms? Or do you mean you want to automatically
set it using the VBA procedure?

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
Peltier Technical Services, Inc. - http://PeltierTech.com
_______


"gibsol" wrote in message
...
I am trying (in Vain) to auto scale bar charts in excel. I have attempted a
macro in VB to do this, but it just seems to do nothing, does not fail or
succeeds. If anyone could take a look at the macro below and assist in
where
it is going wrong would be much appreciated.
Thanks

Sub AutoScaleCharts()

Dim ws As Worksheet
Dim cht As ChartObject
Dim ValuesArray(), SeriesValues As Variant
Dim Ctr As Integer, TotCtr As Integer

For Each ws In ThisWorkbook.Worksheets
For Each cht In ws.ChartObjects
For Each X In cht.Chart.SeriesCollection
SeriesValues = X.Values
ReDim Preserve ValuesArray(1 To TotCtr + UBound(SeriesValues))
For Ctr = 1 To UBound(SeriesValues)
ValuesArray(Ctr + TotCtr) = SeriesValues(Ctr)
Next
TotCtr = TotCtr + UBound(SeriesValues)
Next X
' Reset the minimum and maximum scale to the minimum and
' maximum values in the ValuesArray.
If cht.Chart.HasAxis(xlValue, xlPrimary) Then
cht.Chart.Axes(xlValue, xlPrimary).MinimumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlPrimary).MaximumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlPrimary).MinimumScale =
Application.Min(ValuesArray)
cht.Chart.Axes(xlValue, xlPrimary).MaximumScale =
Application.Max(ValuesArray)
ElseIf cht.Chart.HasAxis(xlValue, xlSecondary) Then
cht.Chart.Axes(xlValue, xlSecondary).MinimumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlSecondary).MaximumScaleIsAuto = True
cht.Chart.Axes(xlValue, xlSecondary).MinimumScale =
Application.Min(ValuesArray)
cht.Chart.Axes(xlValue, xlSecondary).MaximumScale =
Application.Max(ValuesArray)
End If
Next cht
Next ws

End Sub



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatic scaling of charts Alice Graham Charts and Charting in Excel 1 March 6th 07 08:03 PM
Dynamic Scaling for Charts Barb Reinhardt Charts and Charting in Excel 1 August 23rd 05 03:37 PM
Logarithm scaling for charts vroomvondel Charts and Charting in Excel 2 March 16th 05 12:55 AM
Auto Scaling of Y-axis Nicole Charts and Charting in Excel 5 January 5th 05 07:33 PM
Auto Scaling in charts JethroUK© New Users to Excel 3 January 4th 05 03:20 AM


All times are GMT +1. The time now is 04:51 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"