TransWikia.com

VBA Chart set a manuel Y-Axis Scale

Stack Overflow Asked by user9741285 on December 31, 2020

I wrote this method to create 2 charts:

Dim rng As Range
Dim cht As ChartObject
Dim pos As Range



  Set rng = ActiveSheet.Range(data_range)


  Set pos = Range(position)


  Set cht = ActiveSheet.ChartObjects.Add( _
    Left:=pos.Left, _
    Width:=breite, _
    Top:=pos.Top, _
    Height:=hohe)

 
  cht.Chart.HasTitle = True
  cht.Chart.ChartTitle.Text = "Statistik"
  cht.Chart.ChartTitle.Characters.Font.size = 11
  

  cht.Chart.Legend.Delete
  
 
  cht.Chart.SetSourceData Source:=rng

The problem is that when I use this method to create two charts, I have a different Y-Scale values (because of auto-scaling maybe) that makes the comparison difficult:

enter image description here

enter image description here

For this reason I need to set a same value for Y-Axis to have a better result.

2 Answers

I should have added this lines to my code:

Dim yax As Axis


Set yax = cht.Chart.Axes(xlValue)
yax.Minimumscale = 100

Now works everything well.

Correct answer by user9741285 on December 31, 2020

You can try with

cht.Axes(xlValue, xlPrimary).MinimumScale = 0
cht.Axes(xlValue, xlPrimary).MaximumScale = 70

Answered by ECO on December 31, 2020

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP