+ Reply to Thread
Results 1 to 9 of 9

Primary and secondary Y axis should cut X axis at same value

  1. #1
    Registered User
    Join Date
    10-31-2010
    Location
    London
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    56

    Primary and secondary Y axis should cut X axis at same value

    Hi All,

    I have a chart in excel 2010 where the primary Y axis on the left shows returns in % (plotted as a column chart) and the secondary Y axis on the right shows the cumulative return also in % (plotted as a line chart).

    Now the problem I am having is that the secondary Y axis instead of cutting the X-axis at 0 (just like the primary Y axis does) cuts it at some random value. Now to remedy this I set the option 'Horizontal axis crosses at' to 0.0 but this does not seem to work and the secondary Y axis still does not cut the X-axis at 0.

    Any other ideas how this problem can be remedied?

    Thanks
    Last edited by goels; 05-24-2011 at 12:23 PM.

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

    Re: Primary and secondary Y axis should cut X axis at same value

    http://peltiertech.com/Excel/Charts/AlignXon2Ys.html
    Cheers
    Andy
    www.andypope.info

  3. #3
    Registered User
    Join Date
    10-31-2010
    Location
    London
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    56

    Re: Primary and secondary Y axis should cut X axis at same value

    Hi Andy,

    Thanks. I incorporated the code in my sheet and can see option 4 ie input 4 to AlignY function works best for me. As I am not that conversant with VBA can I ask how this code can be modified so that whenever my spreadsheet is opened for the first time option 4 runs for a particular chart (I have several on a worksheet but just want the code to apply to one of them) automatically without having to manually run the macro?

    Thanks

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

    Re: Primary and secondary Y axis should cut X axis at same value

    You can use the Thisworkbook workbook_open event to run code on opening.

  5. #5
    Registered User
    Join Date
    10-31-2010
    Location
    London
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    56

    Re: Primary and secondary Y axis should cut X axis at same value

    Thanks. I have managed to trim the code down to the below:


    Please Login or Register  to view this content.
    The problem I am facing now is how to tell this code that always run for my particular chart. Reading a bit on the internet what I was trying is this code which should activate my chart called Chart5 (I got this name by clicking on the chart and then looking in the name box on top left) but when I run this code it gives all sorts of errors. Am I missing something here?

    Please Login or Register  to view this content.
    Thanks

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

    Re: Primary and secondary Y axis should cut X axis at same value

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Just alter worksheet name from xx to whatever is relavent to your file.

  7. #7
    Registered User
    Join Date
    10-31-2010
    Location
    London
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    56

    Re: Primary and secondary Y axis should cut X axis at same value

    Thanks Andy.

    I have also modified your code a bit to now work when opening a workbook.

    Please Login or Register  to view this content.
    One of the things I am noticing though is that when my workbook is generated from the system that generates it, this code seems to half work as in it aligns the axes at 0 but the secondary axis max value is somewhere on everest and so my line chart based on it disaapears half way. To workaround this I was trying to do the same but when the workbook closes. So using the code

    Please Login or Register  to view this content.
    When trying to run this though I get the Macros window popping up instead of the code executing. Any idea why this might be the case?

    Thanks

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

    Re: Primary and secondary Y axis should cut X axis at same value

    post example workbook that illustrates the problem

  9. #9
    Registered User
    Join Date
    10-31-2010
    Location
    London
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    56

    Re: Primary and secondary Y axis should cut X axis at same value

    For some reason when uploading the .xltm file it does not let me do so.

    Just realised though that when I open the workbook and then close it it does update the chart but for some reason it does not work when I simply try to run the code from the VBA window!
    Guess will just need to live with this mystery...

    But thanks again Andy for all your help

+ 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