Pivot Table Macro
Posted: Thu Oct 08, 2020 1:36 am
Hi
I'm new to the basic macros in Calc. I need to make pivot table from data on sheet. I've got code from this forum and change it a little bit. This is what I've got so far
The result is on this image

However I need to make this Pivot Table exactly like this

What I need to change and how can I move final table to the select sheet? Please help
I'm new to the basic macros in Calc. I need to make pivot table from data on sheet. I've got code from this forum and change it a little bit. This is what I've got so far
Code: Select all
Sub DataPilot
oController = ThisComponent.CurrentController
oSheetObj = oController.ActiveSheet
DataCellRange = oSheetObj.getCellRangeByName("A1:C10")
RangeAddress = DataCellRange.RangeAddress
Tables = oSheetObj.DataPilotTables() 'Tables has all the DataPilot Tables in the Active Sheet
'This part of the code just removes the table if it already exists. Prevents error from running the code several times
If Tables.hasByName("NewDataPilot") THEN
Tables.removeByName("NewDataPilot")
End If
Descriptor = Tables.createDataPilotDescriptor() 'Descriptor contains the description of a DataPilot Table
Descriptor.ShowFilterButton = False 'Don't show the Filter Button
Descriptor.setSourceRange(RangeAddress) 'RangeAddress is defined above to cover A1:C10
Fields = Descriptor.getDataPilotFields
'Set the Enum DataPilotFieldOrientation from com.sun.star.sheet.DataPilotField
Field1 = Fields.getByIndex(0)
Field1.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.ROW
Field2 = Fields.getByIndex(1)
Field2.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.ROW
Field3 = Fields.getByIndex(2)
Field3.Orientation = com.sun.star.sheet.DataPilotFieldOrientation.DATA
Field3.Function = com.sun.star.sheet.GeneralFunction.SUM
Descriptor.RowGrand = "FALSE" 'Turn off the Total line of the Table
Cell = oSheetObj.getCellrangeByName("A15")
Tables.insertNewByName("NewDataPilot", Cell.CellAddress, Descriptor)
End sub

However I need to make this Pivot Table exactly like this

What I need to change and how can I move final table to the select sheet? Please help
