Automatic Ways to Scale an Excel Chart Axis – 2 Methods

This is an overview.

excel chart axis scale automatic

 

Method 1 – Using the Format Axis Feature to Change the Chart Axis Scale in Excel

Step 1: Creating a Dataset for X and Y axis

  • Enter Data in B4 and C4.

Dataset for X and Y axis


Step 2: Insert a 2-D Column Chart

  • Click B4.
  • Go to the Insert tab >> Click scatter and insert the Bar Chart.

Process of generating Bar Chart

The Bar Chart will be displayed.

The Bar Chart


Step 3: Changing the Chart Axis Scale Automatically

  • Select the vertical values of the scatter chart and right click.
  • Select Format Axis.

Selecting "Format Axis" from Bar Chart

  • In Format Axis, select Axis options.
  • In Units >> Enter 3000.

change major unit using Axis Options feature to set chart axis scale

The Maximum Bounds will change to 21000 automatically, and the scale of the y-axis changes will change to 3000.

The value scale of Y-axis changed automatically

  • Observe the GIF below.
  • GIF of changing excel chart axis scale automaticallyYou can’t change the x-axis scale, because text was used instead of values in the horizontal category.
  • In Format Axis you should keep the Axis Type and the Vertical Axis Crosses.

Format Axis option on X-axis

Note

You can also go to Format Axis by right-clicking.

Read More: How to Change Axis Scale in Excel


Method 2 – Running an Excel VBA Code to Change the Chart Axis Scale Automatically

Step 1:

  • Go to the Developer tab.

                                              Developer → Visual Basic

selecting visual basic

  • In Microsoft Visual Basic for Applications, insert a module.

                                                                    Insert → Module

Selection of module

Step 2:

  • Enter the VBA code.
Function ChartAxisScale(sheetName As String, chartName As String, MinOrMax As String, _
    ValueOrCategory As String, PrimaryOrSecondary As String, Value As Variant)
Dim chart As chart
Dim text As String
'Set the function to control the chart
Set chart = Application.Caller.Parent.Parent.Sheets(sheetName) _
    .ChartObjects(chartName).chart
'Set Primary axis Value
If (ValueOrCategory = "Value" Or ValueOrCategory = "Y") _
    And PrimaryOrSecondary = "Primary" Then
    With chart.Axes(xlValue, xlPrimary)
        If IsNumeric(Value) = True Then
            If MinOrMax = "Max" Then .MaximumScale = Value
            If MinOrMax = "Min" Then .MinimumScale = Value
        Else
            If MinOrMax = "Max" Then .MaximumScaleIsAuto = True
            If MinOrMax = "Min" Then .MinimumScaleIsAuto = True
        End If
    End With
End If
'Set Primary axis Category
If (ValueOrCategory = "Category" Or ValueOrCategory = "X") _
    And PrimaryOrSecondary = "Primary" Then
    With chart.Axes(xlCategory, xlPrimary)
        If IsNumeric(Value) = True Then
            If MinOrMax = "Max" Then .MaximumScale = Value
            If MinOrMax = "Min" Then .MinimumScale = Value
        Else
            If MinOrMax = "Max" Then .MaximumScaleIsAuto = True
            If MinOrMax = "Min" Then .MinimumScaleIsAuto = True
        End If
    End With
End If
'Set secondary axis value
If (ValueOrCategory = "Value" Or ValueOrCategory = "Y") _
    And PrimaryOrSecondary = "Secondary" Then
    With chart.Axes(xlValue, xlSecondary)
        If IsNumeric(Value) = True Then
            If MinOrMax = "Max" Then .MaximumScale = Value
            If MinOrMax = "Min" Then .MinimumScale = Value
        Else
            If MinOrMax = "Max" Then .MaximumScaleIsAuto = True
            If MinOrMax = "Min" Then .MinimumScaleIsAuto = True
        End If
    End With
End If
'Set secondary axis category
If (ValueOrCategory = "Category" Or ValueOrCategory = "X") _
    And PrimaryOrSecondary = "Secondary" Then
    With chart.Axes(xlCategory, xlSecondary)
        If IsNumeric(Value) = True Then
            If MinOrMax = "Max" Then .MaximumScale = Value
            If MinOrMax = "Min" Then .MinimumScale = Value
        Else
            If MinOrMax = "Max" Then .MaximumScaleIsAuto = True
            If MinOrMax = "Min" Then .MinimumScaleIsAuto = True
        End If
    End With
End If
If IsNumeric(Value) Then text = Value Else text = "Auto"
ChartAxisScale = ValueOrCategory & " " & PrimaryOrSecondary & " " _
    & MinOrMax & ": " & text
End Function
Sub Axis_Scale()
End Sub

Entering VBA code into the box

 

  • Run the VBA:

                                                 Run → Run Sub/UserForm

Run the VBA code

  • Create a user-defined function.
  • In your Excel sheet, select B20. Enter the user-defined function.

=ChartAxisScale(“Sheet1″,”Chart 2″,”Max”,”Value”,”Primary”,C19)

Entering user defined function to change chart axis scale

Code Breakdown:

This function modifies the properties of the Excel chart axis: sets the minimum or maximum value, or sets it to “Auto”, for the value (Y) or category (X) axis, either on the primary or secondary axis. The function includes 6 parameters:

  1. Sheet name: The name of the sheet that contains the chart
  2. Chart name: The name of the chart to modify
  3. Min Or Max: Whether to set the minimum or maximum value
  4. Value Or Category: Whether to modify the value (Y) or category (X) axis
  5. Primary Or Secondary: Whether to modify the primary or secondary axis
  6. Value: The value to set for the axis

The function returns a string with the final state of the axis.


Download Practice Workbook


Related Articles


<< Go Back to Excel Axis Scale | Excel Charts | Learn Excel

Get FREE Advanced Excel Exercises with Solutions!
Mizbahul Abedin
Mizbahul Abedin

Md Mizbahul Abedin, BSc, Textile Engineering and Management, Bangladesh University of Textiles, has been working with the ExcelDemy project for 11 months. Currently working as an Excel and VBA Content Developer who provides authentic solutions to different Excel-related problems and writes amazing content articles regularly. He has published almost 20 articles in ExcelDemy. He has passions for learning new things about Microsoft Office Suite and Data analysis. Besides, he also likes to travel, photography, international politics, and read... Read Full Bio

We will be happy to hear your thoughts

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo