Results 1 to 6 of 6

Change a (F11) chart's axis values using cell values

Threaded View

  1. #1
    Forum Contributor
    Join Date
    04-02-2017
    Location
    Australia
    MS-Off Ver
    2016
    Posts
    405

    Change a (F11) chart's axis values using cell values

    Hi Guys,

    I want to be able to edit axis of a chart (a "F11" chart not a chart within a sheet) by entering in numbers within cells.
    See the "Chart1 tab" and "Chart2 tab"

    The following code words for a chart within a sheet, but I dont know how to select a chart if that chart is it's own tab.

    Option Explicit
    
    Function setChartAxis(sheetName As String, chartName As String, MinOrMax As String, _
        ValueOrCategory As String, PrimaryOrSecondary As String, Value As Variant)
    
    'create variables
    Dim cht As Chart
    Dim valueAsText As String
    
    'Set the chart to be on the same worksheet as the function
    'Set cht = Application.Caller.Parent.ChartObjects(chartName).Chart
    Set cht = Application.Caller.Parent.Parent.Sheets(sheetName) _
        .ChartObjects(chartName).Chart
    
    
    'Set Value of Primary axis
    If (ValueOrCategory = "Value" Or ValueOrCategory = "Y") _
        And PrimaryOrSecondary = "Primary" Then
    
        With cht.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 Category of Primary axis
    If (ValueOrCategory = "Category" Or ValueOrCategory = "X") _
        And PrimaryOrSecondary = "Primary" Then
    
        With cht.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 value of secondary axis
    If (ValueOrCategory = "Value" Or ValueOrCategory = "Y") _
        And PrimaryOrSecondary = "Secondary" Then
    
        With cht.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 category of secondary axis
    If (ValueOrCategory = "Category" Or ValueOrCategory = "X") _
        And PrimaryOrSecondary = "Secondary" Then
        With cht.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 is text always display "Auto"
    If IsNumeric(Value) Then valueAsText = Value Else valueAsText = "Auto"
    
    'Output a text string to indicate the value
    setChartAxis = ValueOrCategory & " " & PrimaryOrSecondary & " " _
        & MinOrMax & ": " & valueAsText
    
    End Function
    Attached Files Attached Files
    Last edited by JimmyWilliams; 04-05-2020 at 02:26 AM. Reason: clarity
    Thanks,

    JimmyWilliams

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Chart moves bars when axis values change
    By Ochimus in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 04-05-2015, 08:08 AM
  2. [SOLVED] Change x-axis values on Bar Chart
    By scantor145 in forum Excel Charting & Pivots
    Replies: 5
    Last Post: 03-11-2015, 06:45 AM
  3. [SOLVED] How to change y-axis of bubble chart to non-numeric values?
    By arasan25 in forum Excel Charting & Pivots
    Replies: 7
    Last Post: 02-01-2013, 05:16 AM
  4. Change Values on X-axis for Column Chart
    By silliemillie in forum Excel Charting & Pivots
    Replies: 2
    Last Post: 09-24-2007, 11:21 PM
  5. Can't change the scale of values on a y-axis on a line chart
    By ags in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 08-07-2006, 07:40 PM
  6. How do I change X-Axis values in a chart with 2 Y-Axis?
    By ESGLCC in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 05-04-2005, 10:06 AM
  7. How do I change x axis values in a line chart?
    By Elizabeth in forum Excel Charting & Pivots
    Replies: 1
    Last Post: 03-29-2005, 06:06 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1