forked from farishadi/Excel_Macro_References
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPivotTableSample1
More file actions
53 lines (39 loc) · 1.37 KB
/
PivotTableSample1
File metadata and controls
53 lines (39 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
Public Sub PivotTableSample1()
Dim objTable As PivotTable
Dim objField As PivotField
'Pivot table creation algo
Sheets("PGI").Range(Cells(lngFirstRow, intFirstCol), Cells(lngLastRow, intLastCol)).Select
' Create the PivotTable object based on the Employee data on Sheet1.
Set objTable = Sheets("PGI").PivotTableWizard
pivotName = ActiveSheet.PivotTables(1).Name
With ActiveSheet.PivotTables(pivotName)
With .PivotFields("MRP Controller")
.Orientation = xlRowField
.Position = 1
End With
With .PivotFields("Material")
.Orientation = xlRowField
.Position = 2
End With
With .PivotFields("DELIVERYQTY")
.Orientation = xlRowField
.Position = 3
End With
With .PivotFields("Act. Gds Mvmnt Date")
.Orientation = xlRowField
.Position = 4
End With
.PivotFields("MRP Controller").LayoutForm = xlTabular
.PivotFields("Material").LayoutForm = xlTabular
.PivotFields("DELIVERYQTY").LayoutForm = xlTabular
.PivotFields("Act. Gds Mvmnt Date").LayoutForm = xlTabular
.AddDataField ActiveSheet.PivotTables(pivotName).PivotFields("DELIVERYQTY"), "Sum of Qty", xlSum
End With
ActiveSheet.Name = "PGI PivotTable"
ActiveSheet.Cells.EntireColumn.AutoFit
ActiveSheet.Cells.EntireRow.AutoFit
With Cells
.Copy
.PasteSpecial xlPasteValues
End With
Application.CutCopyMode = False