Chart Titles not displaying from VBA - Excel 2013

MacroAlan

New Member
Joined
Aug 30, 2004
Messages
31
I have built the PivotTables from the data and then PivotCharts from them.

My "PrimaryValueAxisTitle" is showing on the wrong data; displaying on the Secondary axis side. And my "SecondaryValueAxisTitle" is not displaying at all. I do not get any error messages.

Got any ideas?

Code:
ActiveSheet.Shapes.AddChart2(201).Select
        ActiveChart.SetSourceData source:=Range("'" & NewSht & "'!A" & LftRow + 3 & ":I" & LastRow)
        ActiveChart.FullSeriesCollection(4).Select
        CurrChrt = ActiveChart.Name
        Cells(LftRow - 2, 10) = CurrChrt
        ActiveChart.FullSeriesCollection(1).ChartType = xlColumnStacked
        ActiveChart.FullSeriesCollection(2).Select
        ActiveChart.SetElement (msoElementDataLabelCenter)  'Bars
        ActiveChart.ChartArea.Select
        ActiveChart.FullSeriesCollection(8).AxisGroup = 2
        ActiveChart.FullSeriesCollection(8).ChartType = xlLine
        ActiveChart.ChartArea.Select
        ActiveChart.SetElement (msoElementDataLabelCenter)
        ActiveChart.ChartArea.Select
        ActiveChart.FullSeriesCollection(8).Select
        ActiveChart.SetElement (msoElementDataLabelRight) 'Line

        ActiveChart.ChartArea.Select
        ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
        Selection.Caption = "Calendar Month Order entered in JDE"
        ActiveChart.SetElement (msoElementSecondaryValueAxisTitleAdjacentToAxis)
        Selection.Caption = "Percentage of Orders that Violated Lead Time" [B] [COLOR="#B22222"]' Not showing[/COLOR][/B]
        ActiveChart.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
        Selection.Caption = "Total Number of Orders"[B] [COLOR="#B22222"]'Showing on wrong side[/COLOR][/B]
        ActiveChart.SetElement (msoElementChartTitleAboveChart)
        Selection.Caption = "Number of Orders vs. Order Lead Time" & vbCr & FltTyp & ": " & Chr(32) & Fliter
        ActiveChart.ChartTitle.Select
        Selection.Format.TextFrame2.TextRange.Font.Bold = msoTrue

ArrNotFound:
 '   Next Z
    LftRow = LftRow + 40
    Z = Z + 1
        RSa.MoveNext
    Loop
    LftRow = 5
    For Z = 1 To ActiveSheet.ChartObjects.Count
        With ActiveSheet.ChartObjects(Z)
            .Left = Range("K" & LftRow).Left
            .Top = Range("K" & LftRow).Top
            .Width = 800
            .Height = 525
[B]  [COLOR="#B22222"]  ' WRONG! Text box needs to be relative to chart
       '     ActiveSheet.Shapes.AddTextbox(msoTextOrientationHorizontal, 489.75, 556.5, 111 _
        , 22.5).Select
      '  Selection.ShapeRange(1).TextFrame2.TextRange.Characters.Text = "Data as of " & Format(Now(), "mm/dd/yy")[/COLOR][/B]
        End With
        LftRow = LftRow + pInterval
    Next Z

And now the customer wants a text box in the chart showing when the data originated.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
I have a solution!
Found something on another site that led me down the true path. To set the Primary and Secondary value titles, they need to be strongly defined:

Code:
        Dim AX          As Axis
        Dim Cht         As Chart
        CurrChrt = ActiveChart.Name
        Set Cht = ActiveSheet.ChartObjects(Right(CurrChrt, 1)).Chart [COLOR="#B22222"]'  09/29 'Get # of chart[/COLOR]
        Cells(LftRow - 2, 10) = CurrChrt
        ActiveChart.FullSeriesCollection(1).ChartType = xlColumnStacked
        ActiveChart.FullSeriesCollection(2).Select
        ActiveChart.SetElement (msoElementDataLabelCenter) [COLOR="#B22222"]'Bars[/COLOR]
        ActiveChart.ChartArea.Select
        ActiveChart.FullSeriesCollection(8).AxisGroup = 2
        ActiveChart.FullSeriesCollection(8).ChartType = xlLine
        ActiveChart.ChartArea.Select
        ActiveChart.SetElement (msoElementDataLabelCenter)
        ActiveChart.ChartArea.Select
        ActiveChart.FullSeriesCollection(8).Select
        ActiveChart.SetElement (msoElementDataLabelRight) [COLOR="#B22222"]'Line[/COLOR]

        ActiveChart.ChartArea.Select
        ActiveChart.SetElement (msoElementPrimaryCategoryAxisTitleAdjacentToAxis)
        Selection.Caption = "Calendar Month Order entered in JDE"
        Cht.SetElement (msoElementPrimaryValueAxisTitleAdjacentToAxis)
        [B]Set AX = Cht.Axes(xlValue, xlPrimary)
        AX.HasTitle = True
        AX.AxisTitle.Format.TextFrame2.TextRange.Characters.Text = "Total Number of Orders"[/B]

       
        [B]Cht.SetElement (msoElementSecondaryValueAxisTitleAdjacentToAxis)
        Set AX = Cht.Axes(xlValue, xlSecondary)
        AX.HasTitle = True
        AX.AxisTitle.Format.TextFrame2.TextRange.Characters.Text = "Percentage of Orders that Violated Lead Time"[/B]

Because I am producing between 2 and 9 charts in a loop I needed to define the ChartObjects(Right(CurrChrt, 1)) number
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top