VBA Set chart axis min and max based on a cell value

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
718
Office Version
  1. 365
Platform
  1. Windows
I have been looking for a VBA function that references 2 cells for my Min and Max Bound values and resets the units after the new Min and Max values are put in.

I have found codes online but the problem is I have 5 charts that I want to do this to and have no idea where to even start modifying these codes. Charts are not my strong suit.

Any help would be greatly appreciated!

Cart 1 is called: "CC"
Max value is located: Sheet: Graph Data, Cell: W17
Min value is located: Sheet: Graph Data, Cell: W18

Cart 2 is called: "Reprocess"
Max value is located: Sheet: Graph Data, Cell: AI40
Min value is located: Sheet: Graph Data, Cell: AI41

Cart 3 is called: "Additional"
Max value is located: Sheet: Graph Data, Cell: AO40
Min value is located: Sheet: Graph Data, Cell: AO41

Cart 4 is called: "DTQ"
Max value is located: Sheet: Graph Data, Cell: AX31
Min value is located: Sheet: Graph Data, Cell: AX32

Cart 5 is called: "TAT"
Max value is located: Sheet: Graph Data, Cell: BA31
Min value is located: Sheet: Graph Data, Cell: BA32

Thank you :)
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

willow1985

Well-known Member
Joined
Jul 24, 2019
Messages
718
Office Version
  1. 365
Platform
  1. Windows
I figured it out.

VBA Code:
' RefreshGraphs Macro
ActiveSheet.ChartObjects("CC").Activate
With Application.ActiveChart.Axes(xlValue, xlPrimary)
.MinimumScale = Sheets("Graph Data").Range("W18").Value
.MaximumScale = Sheets("Graph Data").Range("W17").Value
End With
ActiveSheet.ChartObjects("Reprocess").Activate
With Application.ActiveChart.Axes(xlValue, xlPrimary)
.MinimumScale = Sheets("Graph Data").Range("AI41").Value
.MaximumScale = Sheets("Graph Data").Range("AI40").Value
End With
ActiveSheet.ChartObjects("Additional").Activate
With Application.ActiveChart.Axes(xlValue, xlPrimary)
.MinimumScale = Sheets("Graph Data").Range("AO41").Value
.MaximumScale = Sheets("Graph Data").Range("AO40").Value
End With
ActiveSheet.ChartObjects("DTQ").Activate
With Application.ActiveChart.Axes(xlValue, xlPrimary)
.MinimumScale = Sheets("Graph Data").Range("AX32").Value
.MaximumScale = Sheets("Graph Data").Range("AX31").Value
End With
ActiveSheet.ChartObjects("TAT").Activate
With Application.ActiveChart.Axes(xlValue, xlPrimary)
.MinimumScale = Sheets("Graph Data").Range("BA32").Value
.MaximumScale = Sheets("Graph Data").Range("BA31").Value
End With

End Sub
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,129,688
Messages
5,637,835
Members
416,985
Latest member
mrindira

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
Top