+ Reply to Thread
Results 1 to 11 of 11

Format Secondary Axis to PERCENT

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Format Secondary Axis to PERCENT

    Man.... sometimes I want to pull my hair out...

    If sanitycheck > -1 Then
    'Chart logic
    Dim cdf_livepips As Object
    Dim cfsrs As Series
    
    'Top left draw-down chart
    Set cdf_livepips = ActiveSheet.ChartObjects.Add(Left:=300, Width:=300, Top:=10, Height:=300)
    cdf_livepips.Select
    cdf_livepips.Name = "cdf_livepips"
    'apply series to active chart
    Selection.Name = "cdf_livepips"
    Set ns5 = ActiveChart.SeriesCollection.NewSeries
    'Set ns6 = ActiveChart.SeriesCollection.NewSeries
    ns5.XValues = dd_durationArray
    ns5.Values = dd_arraycdf
    
    
    
    'create the chart dimensions and style
    With cdf_livepips
        .Chart.ChartType = xlXYScatterLines
        .Left = 750
        .Width = 700
        .Top = 350
        .Height = 300
        .Chart.SeriesCollection(1).MarkerStyle = xlLine
        .Chart.SeriesCollection(1).Format.Line.DashStyle = msoLineSysDash
        .Chart.SeriesCollection(1).Border.Weight = xlThin
        .Chart.SeriesCollection(1).MarkerStyle = 1
        .Chart.SetElement (msoElementLegendBottom)
        .Chart.Axes(xlCategory, xlPrimary).TickLabels.NumberFormat = "hh"
        .Chart.Axes(xlCategory, xlSecondary).TickLabels.NumberFormat = Percent
    
    ...
    Why does this not work!?

    run-time error '-21476 bla bla bla....

  2. #2
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP, 2007, 2024
    Posts
    16,399

    Re: Format Secondary Axis to PERCENT

    Doesn't the percent need to be in quotes like the previous statement ....numberformat="percent"?
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  3. #3
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Format Secondary Axis to PERCENT

    Try:
        .Chart.Axes(xlCategory, xlSecondary).TickLabels.NumberFormat = "0.0%"
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  4. #4
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Format Secondary Axis to PERCENT

    Quote Originally Posted by Olly View Post
    Try:
        .Chart.Axes(xlCategory, xlSecondary).TickLabels.NumberFormat = "0.0%"
    Thanks for your input, but nope... i tried this (screenshot: http://screencast.com/t/QZycmSAERUNq)

    Exactly the same error...

  5. #5
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Format Secondary Axis to PERCENT

    You do have a secondary category axis, right? You're not trying to change the secondary VALUE axis?

    Maybe attach your workbook....

  6. #6
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Format Secondary Axis to PERCENT

    Quote Originally Posted by Olly View Post
    You do have a secondary category axis, right? You're not trying to change the secondary VALUE axis?

    Maybe attach your workbook....
    Hm... you know what, I think this maybe where im going wrong. I would attach my sheet but it's massive.

    Literally this is everything I am doing here:

    '------------------------------------------------------------------------------------------------------
    'LIVE - Cumulative Density Function of Draw-down Duration
    '------------------------------------------------------------------------------------------------------
    If sanitycheck > -1 Then
    'Chart logic
    Dim cdf_livepips As Object
    Dim cfsrs As Series
    
    'Top left draw-down chart
    Set cdf_livepips = ActiveSheet.ChartObjects.Add(Left:=300, Width:=300, Top:=10, Height:=300)
    cdf_livepips.Select
    cdf_livepips.Name = "cdf_livepips"
    'apply series to active chart
    Selection.Name = "cdf_livepips"
    Set ns5 = ActiveChart.SeriesCollection.NewSeries
    ns5.XValues = dd_durationArray
    ns5.Values = dd_arraycdf
    
    
    'create the chart dimensions and style
    With cdf_livepips
        .Chart.ChartType = xlXYScatterLines
        .Left = 750
        .Width = 700
        .Top = 350
        .Height = 300
        .Chart.SeriesCollection(1).MarkerStyle = xlLine
        .Chart.SeriesCollection(1).Format.Line.DashStyle = msoLineSysDash
        .Chart.SeriesCollection(1).Border.Weight = xlThin
        .Chart.SeriesCollection(1).MarkerStyle = 1
        .Chart.SetElement (msoElementLegendBottom)
        .Chart.Axes(xlCategory, xlPrimary).TickLabels.NumberFormat = "DD HH HH"
        '.Chart.Axes(xlCategory, xlSecondary).TickLabels.NumberFormat = "Percent"
        .Chart.Axes(xlCategory).TickLabelPosition = xlTickLabelPositionLow
        .Chart.HasTitle = True
        .Chart.ChartTitle.Characters.Text = whichPair & " - Live CDF Draw-down (pips)"
        .Chart.Axes(xlCategory).HasTitle = True
        .Chart.Axes(xlCategory).AxisTitle.Characters.Text = "Duration in drawdown to recovery"
        .Chart.Axes(xlValue).HasTitle = True
        .Chart.Axes(xlValue).AxisTitle.Characters.Text = "Frequency of Occurence"
        .Chart.ChartArea.Fill.Visible = False
        .Chart.PlotArea.Fill.Visible = False
        .Chart.ChartArea.Font.Color = RGB(255, 255, 255)
        .Chart.Axes(xlValue).TickLabels.Font.Size = 8
        .Chart.Axes(xlCategory).TickLabels.Font.Size = 8
        .Chart.ChartArea.Border.LineStyle = xlNone
        .Chart.HasLegend = False
        .Chart.Axes(xlValue).MaximumScale = 1
        .Chart.Axes(xlValue).MinimumScale = 0
    End With
        
    End If

  7. #7
    Forum Guru Winon's Avatar
    Join Date
    02-20-2007
    Location
    East Rand, R.S.A.
    MS-Off Ver
    2010
    Posts
    6,113

    Re: Format Secondary Axis to PERCENT

    I would first try:

    .Chart.Axes(xlCategory, xlSecondary).TickLabels = .Chart.Axes(xlCategory, xlSecondary).TickLabels.Value/100"
    Followed with;

    .Chart.Axes(xlCategory, xlSecondary).TickLabels.NumberFormat = "Percent"
    Last edited by Winon; 08-23-2016 at 11:53 AM. Reason: Waffled BS!
    Please consider:

    Be polite. Thank those who have helped you. Then Click on the star icon in the lower left part of the contributor's post and add Reputation. Cleaning up when you're done. If you are satisfied with the help you have received, then Please do Mark your thread [SOLVED] .

  8. #8
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Format Secondary Axis to PERCENT

    So is it a secondary x-axis, or the primary y-axis that you are trying to format as percent?

    If it's the y-axis, then change that line to:
        .Chart.Axes(xlValue, xlPrimary).TickLabels.NumberFormat = "0.0%"

  9. #9
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Format Secondary Axis to PERCENT

    Quote Originally Posted by Olly View Post
    So is it a secondary x-axis, or the primary y-axis that you are trying to format as percent?

    If it's the y-axis, then change that line to:
        .Chart.Axes(xlValue, xlPrimary).TickLabels.NumberFormat = "0.0%"
    I know this may come across strong considering we're on a forum talking about VBA logic; but I love you...

    One of those days where you're staring at an issue right under your nose.

    On this topic:

    .Chart.Axes(xlCategory, xlPrimary).TickLabels.NumberFormat = "DD HH HH"
    This works fine, however the underlying data is time duration in a fraction (e.g. 4208.28 - 4207.28). I want to illustrate MM:DD:HH however charts dont seem to like this?

  10. #10
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Format Secondary Axis to PERCENT

    Glad that helped!!

    If you want the x-axis labels formatted as "MM:DD:HH" then try:
    .Chart.Axes(xlCategory, xlPrimary).TickLabels.NumberFormat = "mm"":""dd"":""hh"

  11. #11
    Forum Contributor
    Join Date
    10-11-2012
    Location
    England
    MS-Off Ver
    Excel 2010
    Posts
    358

    Re: Format Secondary Axis to PERCENT

    Quote Originally Posted by Olly View Post
    Glad that helped!!

    If you want the x-axis labels formatted as "MM:DD:HH" then try:
    .Chart.Axes(xlCategory, xlPrimary).TickLabels.NumberFormat = "mm"":""dd"":""hh"
    Superb - thank you so much. I was nearly there. I was doing "MM:DD:HH". Not sure why this doesnt work this way?

    Kudos to you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 2
    Last Post: 10-08-2014, 08:04 PM
  2. format 2 or more dataseries to secondary axis
    By Bandini in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 09-30-2014, 02:37 AM
  3. Replies: 4
    Last Post: 05-17-2012, 11:25 AM
  4. Secondary Y axis title and format problem
    By oro77 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 02-28-2012, 05:24 AM
  5. Replies: 0
    Last Post: 06-13-2011, 11:11 AM
  6. Replies: 6
    Last Post: 12-07-2010, 02:54 PM
  7. Pivot Table, Line Chart with Secondary Y axis, Page Field selection destroys Y2 axis
    By mw210461@yahoo.com in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 07-13-2005, 05:05 PM

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