I need some assistance, adding a Pivot Chart to each sheet that has the name Data.
OLD CODE:
- 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 | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
A | B | C | D | E | F | G | H | I | J | K | L | M | N | O | P | Q | R | |||
1 | ||||||||||||||||||||
2 | CH | Obj | Session | SessionDate | Probe# | Employee | Not Checked | Score | Alpha | Beta | Delta | Kappa | Pi | Xi | Note | |||||
3 | 1 | 3 | 1 | 8/15/2022 | 1 | Sam | 0 | 6 | 0 | 0 | 0 | 0 | 0 | 26-50% | ||||||
4 | 1 | 3 | 1 | 8/15/2022 | 2 | Sam | 0 | 5 | 0 | 0 | 1 | 0 | 0 | 26-50% | ||||||
5 | 1 | 3 | 1 | 8/15/2022 | 3 | Sue | 0 | 5 | 0 | 0 | 0 | 1 | 0 | 26-50% | ||||||
6 | 1 | 3 | 1 | 8/15/2022 | 4 | Michael | 0 | 5 | 0 | 0 | 1 | 0 | 0 | 26-50% | ||||||
7 | 1 | 3 | 1 | 8/15/2022 | 5 | Sam | 0 | 5 | 0 | 0 | 1 | 0 | 0 | 26-50% | Really cool notes! | |||||
8 | 1 | 3 | 2 | 9/5/2022 | 1 | Michael | 0 | 5 | 0 | 0 | 1 | 0 | 0 | 51-75% | ||||||
9 | 1 | 3 | 2 | 9/5/2022 | 2 | Sue | 0 | 5 | 0 | 0 | 0 | 1 | 0 | 51-75% | ||||||
10 | 1 | 3 | 2 | 9/5/2022 | 3 | David | 0 | 5 | 0 | 0 | 1 | 0 | 0 | 51-75% | ||||||
11 | 1 | 3 | 2 | 9/5/2022 | 4 | Sue | 0 | 3 | 5 | 0 | 0 | 0 | 6 | 51-75% | ||||||
12 | 1 | 3 | 2 | 9/5/2022 | 5 | Michael | 0 | 1 | 0 | 7 | 7 | 0 | 0 | 51-75% | ||||||
13 | ||||||||||||||||||||
14 | ||||||||||||||||||||
15 | ||||||||||||||||||||
16 | ||||||||||||||||||||
17 | Row Labels | Sum of Score | ||||||||||||||||||
18 | 8/15/2022 | 26 | ||||||||||||||||||
19 | 1 | 26 | ||||||||||||||||||
20 | 1 | 6 | ||||||||||||||||||
21 | 2 | 5 | ||||||||||||||||||
22 | 3 | 5 | ||||||||||||||||||
23 | 4 | 5 | ||||||||||||||||||
24 | 5 | 5 | ||||||||||||||||||
25 | 9/5/2022 | 19 | ||||||||||||||||||
26 | 2 | 19 | ||||||||||||||||||
27 | 1 | 5 | ||||||||||||||||||
28 | 2 | 5 | ||||||||||||||||||
29 | 3 | 5 | ||||||||||||||||||
30 | 4 | 3 | ||||||||||||||||||
31 | 5 | 1 | ||||||||||||||||||
32 | Grand Total | 45 | ||||||||||||||||||
33 | ||||||||||||||||||||
34 | ||||||||||||||||||||
35 | ||||||||||||||||||||
36 | ||||||||||||||||||||
37 | ||||||||||||||||||||
38 | ||||||||||||||||||||
39 | ||||||||||||||||||||
40 | ||||||||||||||||||||
41 | ||||||||||||||||||||
42 | ||||||||||||||||||||
43 | ||||||||||||||||||||
44 | ||||||||||||||||||||
45 | ||||||||||||||||||||
Data1 |