Solved

Pivot Chart

Posted on 2013-06-04
5
502 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

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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