+ Reply to Thread
Results 1 to 4 of 4

How to automatically control the x and y axis of an xy scatter chart

  1. #1
    Registered User
    Join Date
    04-23-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2003
    Posts
    2

    How to automatically control the x and y axis of an xy scatter chart

    I have a single xy scatter chart in which I want to control the max, min, and unit of the x and y axis. I am new to VBA and so far have gotten the y axis (price), but not the x axis (date) to work, when added later. I appreciate your help.

    Sub ChangeChartScales()
    Dim objCht As ChartObject
    For Each objCht In ActiveSheet.ChartObjects
    With objCht.Chart
    With .Axes(xlValue)
    .MinimumScale = ActiveSheet.Range("DC_yMin").Value
    .MaximumScale = ActiveSheet.Range("DC_yMax").Value
    .MajorUnit = ActiveSheet.Range("DC_yUnit").Value
    End With
    With .Axes(xlCategory)
    .MinimumScale = ActiveSheet.Range("DC_xMin").Value
    .MaximumScale = ActiveSheet.Range("DC_xMax").Value
    .MajorUnit = ActiveSheet.Range("DC_xUnit").Value
    End With
    End With
    Next objCht
    End Sub

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,438

    Re: How to automatically control the x and y axis of an xy scatter chart

    It would help if you posted example workbook to illustrate your problem.
    The code looks like it should work.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    04-23-2012
    Location
    Houston, Texas
    MS-Off Ver
    Excel 2003
    Posts
    2

    Re: How to automatically control the x and y axis of an xy scatter chart

    I created a simple example spreadsheet; however, it worked in that case, so I didn't post it. In my actual file I am using named ranges for the data for both axis so that it is dynamic, could that create any problems when dealing with dates as a data element for the x axis?

    Here is my named range for the X axis:

    Cash_calendar: =OFFSET(Cash!$B$14,0,0,COUNTA(Cash!$B$14:$B$44))

    to create the DC_xMax I am taking =Max(Cash_calendar)+1
    Last edited by JJP2; 04-24-2012 at 05:22 PM.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,438

    Re: How to automatically control the x and y axis of an xy scatter chart

    Really can't help without an example with failing data but otherwise if I create an example, like you discovered, it will no doubt work.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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