Link Chart Axis to Cell Value

pagrender

Well-known Member
Joined
Sep 3, 2008
Messages
652
Hello all,

I ran into some issues regarding how Excel automatically scaled some of my charts - mainly I didn't like how it determined what should be the maximum or the minimum values of the Y axis of my Line chart.

Manually changing the scaling isn't an option I would like to pursue as when my project is done I will have about 800 charts in numerous files.

I found some VB code out on a website where I can enter a value in a cell and have that value go to the chart (http://en.allexperts.com/q/Excel-1059/2008/11/Link-Chart-Axis-Formulas.htm), modified it just a bit, but I cannot make it work.

Here is the code I have:
Sub minMax()
Dim wks As Worksheet
Dim cht As ChartObject
Set wks = ThisWorkbook.Sheets("Charts")
Set cht = wks.ChartObjects("Chart 3")
cht.Chart.Axes(xlValue).MinimumScale = wks.Range("a1")
cht.Chart.Axes(xlValue).MaximumScale = wks.Range("b1")
End Sub

In A1 on the "Charts" sheet, I entered my minimum and in B1 I entered the maximum.

When I run the macro, the Y axis changes to a bunch of zeros and negative ones, along with moving the Y axis to the top of the chart.

Can someone help me fix this code?

Thanks,
Pete
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Does anyone have any suggestions how fix this code? Or do they have their own code suggestion?
 
Upvote 0

Forum statistics

Threads
1,214,520
Messages
6,120,013
Members
448,935
Latest member
ijat

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