Solved

Pivot Chart

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Outlook Free & Paid Tools
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

707 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

17 Experts available now in Live!

Get 1:1 Help Now