Adjusting Chart Minimum and Maximum values via VBA

frabulator

Board Regular
Joined
Jun 27, 2014
Messages
248
Office Version
  1. 2019
Platform
  1. Windows
I have been trying use a userform to adjust the minimum and maximum value scale on a chart. The problem is that my code keeps saying that "Method 'MinimumScale' of object 'Axis' not found" when trying to resize.

How I am accessing the graph is by first having the user click on the graph (with the macro below):

Code:
Sub OpenZoomPan(control As IRibbonControl)

    Dim selectionType As String
    
      If TypeName(Selection) = "ChartArea" Or TypeName(Selection) = "PlotArea" Then
        Set chart_from_selection = Selection.Parent
        UserForm9.Show
      ElseIf TypeName(Selection) = "Series" Then
        Set chart_from_selection = Selection.Parent.Parent
        UserForm9.Show
      Else
        MsgBox ("Please select a chart to continue.")
      End If

    
End Sub

The above code works great. Then I adjust the scroll bar as needed and run the code below:

Code:
Sub ZoomAndPann()

    application.ScreenUpdating = False


    'X
    Dim mx As Double
    mx = UserForm9.Original_X_min - (UserForm9.Original_X_min * (UserForm9.ScrollBar3.Value / (UserForm9.ScrollBar3.Max / 2)))
    Dim xx As Double
    xx = UserForm9.Original_X_max - (UserForm9.Original_X_max * (UserForm9.ScrollBar3.Value / (UserForm9.ScrollBar3.Max / 2)))

    Dim AcSh As String
    AcSh = chart_from_selection.Name
    AcSh = Mid(AcSh, Len(ActiveSheet.Name) + 2, Len(AcSh) - (Len(ActiveSheet.Name) + 1))
    
    
    ActiveSheet.ChartObjects(AcSh).Activate
    
    'X
    ActiveChart.Axes(xlValue).MinimumScale = mx
    ActiveChart.Axes(xlValue).MaximumScale = xx
    
    'Y
    ActiveChart.Axes(xlCategory).MinimumScale = mx
    ActiveChart.Axes(xlCategory).Select
    ActiveChart.Axes(xlCategory).MaximumScale = xx
    
    

    application.ScreenUpdating = True
    
End Sub

The line that is acting up is 'ActiveChart.Axes(xlValue).MinimumScale = mx'. I know i have the chart selected because 'ActiveSheet.ChartObjects(AcSh).Activate' is firing and AcSh is collecting the name of the chart in question.

Any help on this would be greatly appreciated. I'm sure it is something silly that I am over looking but I have been stuck on this for days.

~Frab
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Re: Help with adjusting Chart Minimum and Maximum vales via VBA

Update*

I just tried to swap the xlValue code with the xlCategory code to see if it was an axis selection issue, turns out both of these axis give the same error.
 
Upvote 0
Re: Help with adjusting Chart Minimum and Maximum vales via VBA

Bump
 
Upvote 0
Re: Help with adjusting Chart Minimum and Maximum vales via VBA

Bump
 
Upvote 0
Re: Help with adjusting Chart Minimum and Maximum vales via VBA

Bump
 
Upvote 0
Re: Help with adjusting Chart Minimum and Maximum vales via VBA

bump
 
Upvote 0
Re: Help with adjusting Chart Minimum and Maximum vales via VBA

no problem here . .
what is the value of mx?
 
Upvote 0
Re: Help with adjusting Chart Minimum and Maximum vales via VBA

no problem here . .
what is the value of mx?

That is good to know that it is working on your end. That must mean there is something wrong with my macro/userform macro transfer or three way transfer from sheet to macro to userform.

The variable in question is arbitrary. The value itself has been equated to '-3.5' for mx and '3.5' for xx. The reason why I say it doesn't matter is I have replace the place holders with actual values and still get the same result.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,522
Messages
6,120,020
Members
448,938
Latest member
Aaliya13

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