Solved

Pivot Chart

Posted on 2013-06-04
5
492 Views
Last Modified: 2013-06-10
Hi team,
I am trying to create a pivot chart using a macro, but when I got the result after doing recording macro I got this, but when I was trying to rerun again I got Run-time-error 1004.
Application-defined or object-defined error.

Thanks for your help.

Sub Macro1()
'
' Macro1 Macro
'

'
    Columns("A:G").Select
    Sheets.Add
    ActiveWorkbook.Worksheets("Sheet4").PivotTables("PivotTable3").PivotCache. _
        CreatePivotTable TableDestination:="Sheet2!R1C1", TableName:="PivotTable1" _
        , DefaultVersion:=xlPivotTableVersion14
    Sheets("Sheet2").Select
    Cells(1, 1).Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=Range("Sheet2!$A$1:$C$18")
    ActiveSheet.Shapes("Chart 1").IncrementLeft 192
    ActiveSheet.Shapes("Chart 1").IncrementTop 12.75
    Sheets("Sheet2").Select
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Data Analysis")
        .Orientation = xlRowField
        .Position = 1
    End With
    Sheets("Sheet2").Name = "Scorecard"
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Data Analysis")
        .PivotItems("FALSE").Visible = False
        .PivotItems("(blank)").Visible = False
    End With
    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Cycle")
        .Orientation = xlColumnField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
        "PivotTable1").PivotFields("Shipset"), "Count of Shipset", xlCount
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveSheet.Shapes("Chart 1").IncrementLeft 181.5
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveSheet.Shapes("Chart 1").IncrementLeft 50.25
    ActiveSheet.Shapes("Chart 1").IncrementTop -6.75
    ActiveSheet.ChartObjects("Chart 1").Activate
    With ActiveSheet.Shapes("Chart 1").Line
        .Visible = msoTrue
        .ForeColor.ObjectThemeColor = msoThemeColorAccent1
        .ForeColor.TintAndShade = 0
        .ForeColor.Brightness = 0
    End With
    Range("A2").Select
    ActiveSheet.PivotTables("PivotTable1").CompactLayoutRowHeader = _
        "Shipment analysis"
    Range("B1").Select
    ActiveSheet.PivotTables("PivotTable1").CompactLayoutColumnHeader = "Cycle Time"
    Range("B2").Select
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ApplyLayout (1)
    ActiveSheet.ChartObjects("Chart 1").Activate
    ActiveChart.ChartTitle.Select
    ActiveChart.ClearToMatchStyle
    ActiveChart.ChartStyle = 34
    ActiveChart.ClearToMatchStyle
    ActiveChart.ChartTitle.Text = "Shipment Process Analysis"
    Selection.Format.TextFrame2.TextRange.Characters.Text = _
        "Shipment Process Analysis"
    With Selection.Format.TextFrame2.TextRange.Characters(1, 25).ParagraphFormat
        .TextDirection = msoTextDirectionLeftToRight
        .Alignment = msoAlignCenter
    End With
    With Selection.Format.TextFrame2.TextRange.Characters(1, 25).Font
        .BaselineOffset = 0
        .Bold = msoTrue
        .NameComplexScript = "+mn-cs"
        .NameFarEast = "+mn-ea"
        .Fill.Visible = msoTrue
        .Fill.ForeColor.RGB = RGB(0, 0, 0)
        .Fill.Transparency = 0
        .Fill.Solid
        .Size = 18
        .Italic = msoFalse
        .Kerning = 12
        .Name = "+mn-lt"
        .UnderlineStyle = msoNoUnderline
        .Strike = msoNoStrike
    End With
    ActiveChart.ChartArea.Select
End Sub

Open in new window

0
Comment
Question by:gfranco
  • 3
5 Comments
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 39235260
Two things:

1) Can you post a (sanitized) sample file?

2) When the error comes up, click Debug, and then tell us which line you jump to in the VB Editor
0
 

Author Comment

by:gfranco
ID: 39235686
I used save macro and pasted as a sub, but when I was trying to rerun. I could not do it.
Thanks.
0
 

Author Comment

by:gfranco
ID: 39235693
Please, just renamed the file as .xlsx
Sheet 4 is the example that I am trying to accomplish.


thanks.
Pivot.txt
0
 

Author Closing Comment

by:gfranco
ID: 39236130
Thanks It went trough
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now