Sub CF_PivotTable()
' CREATE A PIVOT TABLE FROM THE NON DISCOUNT INVOICES
Sheets.Add
ActiveSheet.Name = "Summary"
Sheets("Summary list - all open items b").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 0).Select
lRow = ActiveCell.Row
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Summary list - all open items b!R1C1:R" & lRow & "C11", Version:= _
xlPivotTableVersion10).CreatePivotTable TableDestination:="Summary!R1C1", _
TableName:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
Sheets("Summary").Select
Cells(1, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Net due dt")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Amount in local cur."), _
"Sum of Amount in local cur.", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Status")
.Orientation = xlColumnField
.Position = 1
End With
ActiveWorkbook.ShowPivotTableFieldList = False
ActiveCell.Offset(0, 1).Columns("A:C").EntireColumn.Select
Selection.Style = "Comma"
ActiveCell.Offset(1, 3).Range("A1").Select
Sheets.Add
' CREATE A PIVOT TABLE FROM THE DISCOUNT INVOICES
ActiveSheet.Name = "Discount Summary"
Sheets("Discount list - all open items").Select
Rows("1:1").Select
Selection.Insert Shift:=xlDown, CopyOrigin:=xlFormatFromLeftOrAbove
Range("A1").Select
Sheets("Summary list - all open items b").Select
Rows("1:1").Select
Selection.Copy
Sheets("Discount list - all open items").Select
ActiveSheet.Paste
Range("A1").Select
Sheets("Discount list - all open items").Select
Range("A1").Select
Selection.End(xlDown).Select
ActiveCell.Offset(0, 0).Select
lRow = ActiveCell.Row
Range("A1").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlToRight)).Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"Discount list - all open items!R1C1:R" & lRow & "C11", Version:= _
xlPivotTableVersion10).CreatePivotTable TableDestination:="Discount Summary!R1C1", _
TableName:="PivotTable2", DefaultVersion:=xlPivotTableVersion10
Sheets("Discount Summary").Select
Cells(1, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Net due dt")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("Amount in local cur."), _
"Sum of Amount in local cur.", xlSum
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Status")
.Orientation = xlColumnField
.Position = 1
End With
ActiveWorkbook.ShowPivotTableFieldList = False
Columns("B:D").Select
Selection.Style = "Comma"
Range("E3").Select
End Sub
|