vba chart legend position & x and y min and max

Boogerbut74

New Member
Joined
Oct 17, 2022
Messages
26
Office Version
  1. 365
Platform
  1. Windows
I'm trying to set the legend below the x axis and to set a min and max for the x and y axis

VBA Code:
Sub base_graph_creator()
'Your data range for the chart

Dim rng As Range
Dim cht As ChartObject
  Set rng = ActiveSheet.Range("D10:V2363")

'Create a chart
  Set cht = ActiveSheet.ChartObjects.Add( _
    Left:=ActiveCell.Left, _
    Width:=450, _
    Top:=ActiveCell.Top, _
    Height:=250)



'Give chart some data
  cht.Chart.SetSourceData Source:=rng

'Determine the chart type
  
  cht.Chart.ChartType = xlXYScatterLines

' this makes the x axis min and max
  
cht.Chart.Axes(xlCategory).MinimumScale = 0
cht.Chart.Axes(xlCategory).MaximumScale = 100

' this makes the y axis min and max
ActiveChart.Chart.Axes(ylCategory).MinimumScale = 115
ActiveChart.Chart.Axes(ylCategory).MaximumScale = 140

' this changes legend position
ActiveChart.Legend.Position = xlLegendPositionBottom
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
It should be as follows...

VBA Code:
' this makes the y axis min and max
cht.Chart.Axes(xlValue).MinimumScale = 115
cht.Chart.Axes(xlValue).MaximumScale = 140

and

VBA Code:
' this changes legend position
cht.Chart.Legend.Position = xlLegendPositionBottom

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,214,591
Messages
6,120,426
Members
448,961
Latest member
nzskater

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top