Guest User

Untitled

a guest
May 28th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. $xlRowField = 1
  2. $xlColumnField = 2
  3. $xlDataField = 4
  4. $xlCount = -4112
  5.  
  6. $Excel.Visible = $True
  7. $outputWorkBook = $Excel.Workbooks.Open("FILENAME.xlsx", $True, $True)
  8. pivotTable = $outputWorkBook.ActiveSheet.PivotTableWizard()
  9.  
  10. $pivotTable.PivotFields("columnWithNumbers").Orientation = [int]$xlRowField
  11. $pivotTable.PivotFields("filename").Orientation = [int]$xlColumnField
  12.  
  13. $pivotDataCount = $pivotTable.PivotFields("columnWithNumbers")
  14. $pivotDataCount.Orientation = [int]$xlDataField
  15. $pivotDataCount.Function = [int]$xlCount
  16.  
  17. Sub Macro1()
  18. '
  19. ' Macro1 Macro
  20. '
  21.  
  22. '
  23. Sheets.Add
  24. ActiveWorkbook.Worksheets("Sheet2").PivotTables("PivotTable1").PivotCache. _
  25. CreatePivotTable TableDestination:="Sheet4!R3C1", TableName:="PivotTable3" _
  26. , DefaultVersion:=6
  27. Sheets("Sheet4").Select
  28. Cells(3, 1).Select
  29. With ActiveSheet.PivotTables("PivotTable3")
  30. .ColumnGrand = True
  31. .HasAutoFormat = True
  32. .DisplayErrorString = False
  33. .DisplayNullString = True
  34. .EnableDrilldown = True
  35. .ErrorString = ""
  36. .MergeLabels = False
  37. .NullString = ""
  38. .PageFieldOrder = 2
  39. .PageFieldWrapCount = 0
  40. .PreserveFormatting = True
  41. .RowGrand = True
  42. .SaveData = True
  43. .PrintTitles = False
  44. .RepeatItemsOnEachPrintedPage = True
  45. .TotalsAnnotation = False
  46. .CompactRowIndent = 1
  47. .InGridDropZones = False
  48. .DisplayFieldCaptions = True
  49. .DisplayMemberPropertyTooltips = False
  50. .DisplayContextTooltips = True
  51. .ShowDrillIndicators = True
  52. .PrintDrillIndicators = False
  53. .AllowMultipleFilters = False
  54. .SortUsingCustomLists = True
  55. .FieldListSortAscending = False
  56. .ShowValuesRow = False
  57. .CalculatedMembersInFilters = False
  58. .RowAxisLayout xlCompactRow
  59. End With
  60. With ActiveSheet.PivotTables("PivotTable3").PivotCache
  61. .RefreshOnFileOpen = False
  62. .MissingItemsLimit = xlMissingItemsDefault
  63. End With
  64. ActiveSheet.PivotTables("PivotTable3").RepeatAllLabels xlRepeatLabels
  65. With ActiveSheet.PivotTables("PivotTable3").PivotFields("id")
  66. .Orientation = xlRowField
  67. .Position = 1
  68. End With
  69. With ActiveSheet.PivotTables("PivotTable3").PivotFields("filename")
  70. .Orientation = xlColumnField
  71. .Position = 1
  72. End With
  73. ActiveSheet.PivotTables("PivotTable3").AddDataField ActiveSheet.PivotTables( _
  74. "PivotTable3").PivotFields("id"), "Sum of id", xlSum
  75. With ActiveSheet.PivotTables("PivotTable3").PivotFields("Sum of id")
  76. .Caption = "Count of id"
  77. .Function = xlCount
  78. End With
  79. Range("A5").Select
  80. ActiveSheet.PivotTables("PivotTable3").PivotFields("id").PivotFilters.Add2 _
  81. Type:=xlValueIsGreaterThan, DataField:=ActiveSheet.PivotTables( _
  82. "PivotTable3").PivotFields("Count of id"), Value1:=1
  83. End Sub
Add Comment
Please, Sign In to add comment