View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default Scaling Axis via VBA?

You don't need to go as far as the data source range. Iterate through the
series and find the min and max values:

Dim srs As Series
Dim xMin As Double
Dim xMax As Double
Dim yMin As Double
Dim yMax As Double

With ActiveChart.SeriesCollection(1)
xMin = WorksheetFunction.Minimum(.XValues)
xMax = WorksheetFunction.Maximum(.XValues)
yMin = WorksheetFunction.Minimum(.Values)
yMax = WorksheetFunction.Maximum(.Values)
End With
For Each srs In ActiveChart.SeriesCollection
With ActiveChart.SeriesCollection(1)
If xMin WorksheetFunction.Minimum(.XValues) Then xMin =
WorksheetFunction.Minimum(.XValues)
If xMax < WorksheetFunction.Maximum(.XValues) Then xMax =
WorksheetFunction.Maximum(.XValues)
If yMin WorksheetFunction.Minimum(.Values) Then yMin =
WorksheetFunction.Minimum(.Values)
If yMax < WorksheetFunction.Maximum(.Values) Then yMax =
WorksheetFunction.Maximum(.Values)
End With
Next

Given these min and max data values, you can use Stephen Bullen's technique
to calculate decent min, max, and major chart scale units:

http://groups.google.com/group/micro...13d5257af6a8c7

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


"(PeteCresswell)" wrote in message
...
I'm creating a spreadsheet with many charts.

Each chart may have a different range of values - "Deal Count", for
instance,
may vary from 1 to 10 on one chart, but from 1 to 145 on another chart.

I want to set each chart's Axis.MajorUnitScale to an appropriate amount.

I'm figuring something like:
---------------------------------
Count < 10 = 1
Count between 11 and 100 = 10
Count between 101 and 1000 = 100
---------------------------------

And so-on....

Do I have to go to each chart's data range, figure out which column has
"Deal
Count" in it, figure out how many rows there are, and then do a Max()?

Or is there some simpler way?

The exact MajorUnitScale isn't a religious issue - I just want it so that
the
tick mark labels aren't all scrunched together.
--
PeteCresswell