0

so I am wondering how to scale a chart so that the minimum value of the y-axis becomes the minimum value between all the series that are on the chart. Here is the code that I am working with:

 Sub This() With Sheets("Plots").ChartObjects("The Chart").Chart.Axes(xlValue) For i = ActiveChart.SeriesCollection.Count To 1 Step -1 **find minimum value** Next i .MinimumScale = miny End With End Sub 
3
  • 1
    Why not find the minimum value in the data set itself rather than going through the chart? Commented Jul 7, 2016 at 20:00
  • The code as written will also not work if the ActiveChart is different from The Chart. Read More about With ... End With Blocks Commented Jul 7, 2016 at 20:02
  • I have a bunch of charts so I thought that this would be easier. Also because the data is in a bunch of different ranges. I am also kind of interested in this problem now. Commented Jul 7, 2016 at 20:03

2 Answers 2

4
Sub Tester() Dim cht As Chart Dim s As Series, mins(), x Set cht = Sheets("Plots").ChartObjects("The Chart").Chart ReDim mins(1 To cht.SeriesCollection.Count) x = 1 For Each s In cht.SeriesCollection mins(x) = Application.Min(s.Values) x = x + 1 Next s cht.Axes(xlValue).MinimumScale = Application.Min(mins) End Sub 
Sign up to request clarification or add additional context in comments.

1 Comment

this is fantastic! Thank you for the help!
1
Dim maxv As Double = objChart.Axes(XlAxisType.xlValue).MaximumScale() Dim minv As Double = objChart.Axes(XlAxisType.xlValue).MinimumScale() 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.