We help IT Professionals succeed at work.
Get Started

Macro Excel that create a pivot table and a chart on different sheets

mldaigle1
mldaigle1 asked
on
160 Views
Last Modified: 2016-02-10
Hi,

Is it possible to create the pivot table on one sheet and the chart of the same data on a different sheet?
Below is my code for creating the pivot table... but i don't know how to create my chart from there...

***************************************

Sub PivotType()

' Create pivot table for type of computers
    Sheets("Inventaire").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
        SourceData:=ActiveSheet.UsedRange, Version:=xlPivotTableVersion15). _
        CreatePivotTable TableDestination:="PivotTable!R2C1", TableName:= _
        "PivotTable1", DefaultVersion:=xlPivotTableVersion15
   
    Sheets("PivotTable").Select
    Cells(2, 1).Select
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(2, 1)
    ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:="Type"
    ActiveSheet.PivotTables("PivotTable1").PivotFields("Type").Orientation = xlDataField

    With ActiveSheet.PivotTables("PivotTable1").PivotFields("Type")
        .Orientation = xlRowField
        .Position = 1
    End With
   
    Range("A2").Select
    ActiveSheet.PivotTables("PivotTable1").CompactLayoutRowHeader = "Type"
    Range("B2").Select
    ActiveSheet.PivotTables("PivotTable1").DataPivotField.PivotItems( _
        "Count of Type").Caption = "Qty"
    Range("B2").Select
    With Selection
        .HorizontalAlignment = xlRight
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .IndentLevel = 0
        .ShrinkToFit = False
        .ReadingOrder = xlContext
        .MergeCells = False
    End With
Comment
Watch Question
Consultant
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 4 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE