Format Axis Maximum by Cell Value

Anonymous
2022-02-10T22:44:51+00:00

I have a an X Y line chart where the lines are the comparison values, and I plot a few data points. I want to format the x axis to variable maximum value that is lower than the maximum in the data range. Some of the data shows comparison values so it is ok if it is cut off. How do I get the maximum x axis value to be based on a cell value?

Microsoft 365 and Office | Excel | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. HansV 462.4K Reputation points MVP Volunteer Moderator
    2022-02-11T17:22:10+00:00

    You need to change Range("D38:D39") in the code to the cell or cells that you enter manually and that determine the outcome of the formula in D2.

    Alternatively, use this code, but it has a higher overhead:

    Private Sub Worksheet_Calculate()
        On Error GoTo ErrHandler
        Me.ChartObjects(1).Chart.Axes(xlCategory).MaximumScale = Range("D2").Value
        Exit Sub
    ErrHandler:
        MsgBox Err.Description, vbExclamation
    End Sub
    
    1 person found this answer helpful.
    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Anonymous
    2022-02-11T17:58:32+00:00

    That one works for me. Thank you!

    0 comments No comments