VBA - Multiple Sheets - Create Pivot Charts on each sheet

LNG2013

Active Member
Joined
May 23, 2011
Messages
466
I need some assistance, adding a Pivot Chart to each sheet that has the name Data.
  • There can be Multiple sheets each named "Data", with a number value after. The number values start at 0, and can go to 10. Example "Data0," "Data1," "Data2," etc
  • On each sheet the data spans from A2-O LastRow. I use B column to designate the last row for O. This varies on each Data Sheet. One may be 50 rows long, 1 may be zero,
  • I'd like to add the Pivot chart 4 rows after the last data on column B
  • The Pivot Chart uses Row Labels of SessionDate, Sesion, Probe#, and Values of Sum of Score.
  • Below is a recording of the Macro to create the Pivot table on an individual Data 1 page


OLD CODE:
VBA Code:
Sub Macro1()

'
    Range("A2:O12").Select
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
        "Data1!R2C1:R12C15", Version:=xlPivotTableVersion14).CreatePivotTable _
        TableDestination:="Data1!R16C2", TableName:="PivotTable2", DefaultVersion _
        :=xlPivotTableVersion14
    Sheets("Data1").Select
    Cells(16, 2).Select
    ActiveSheet.Shapes.AddChart.Select
    ActiveChart.ChartType = xlColumnClustered
    ActiveChart.SetSourceData Source:=Range("Data1!$B$16:$D$33")
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("SessionDate")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("Session")
        .Orientation = xlRowField
        .Position = 2
    End With
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("Probe#")
        .Orientation = xlRowField
        .Position = 3
    End With
    ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
        "PivotTable2").PivotFields("Score"), "Sum of Score", xlSum
    ActiveSheet.Shapes("Chart 2").IncrementLeft -325.5
    ActiveSheet.Shapes("Chart 2").IncrementTop -67.5
    ActiveChart.ChartType = xlLineMarkers
End Sub

UploadTest.xlsx
ABCDEFGHIJKLMNOPQR
1
2CHObjSessionSessionDateProbe#EmployeeNot CheckedScoreAlphaBetaDeltaKappaPiXiNote
31318/15/20221Sam060000026-50%
41318/15/20222Sam050010026-50%
51318/15/20223Sue050001026-50%
61318/15/20224Michael050010026-50%
71318/15/20225Sam050010026-50%Really cool notes!
81329/5/20221Michael050010051-75%
91329/5/20222Sue050001051-75%
101329/5/20223David050010051-75%
111329/5/20224Sue035000651-75%
121329/5/20225Michael010770051-75%
13
14
15
16
17Row LabelsSum of Score
188/15/202226
19126
2016
2125
2235
2345
2455
259/5/202219
26219
2715
2825
2935
3043
3151
32Grand Total45
33
34
35
36
37
38
39
40
41
42
43
44
45
Data1
 

Attachments

  • 2022-10-06 17_08_56-.png
    2022-10-06 17_08_56-.png
    50.8 KB · Views: 21

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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