Sub 创建透视表() dim nosubtotal as variant nosubtatal=array(false,false,false,false,false,false,false,false,false,false,false,false) ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:="铜购进"). _ CreatePivotTable TableDestination:=ActiveSheet.Cells(3, 1), TableName _ :="数据透视表1", DefaultVersion:=xlPivotTableVersion10 ActiveWorkbook.ShowPivotTableFieldList = True With ActiveSheet.PivotTables("数据透视表1").PivotFields("日期") .Orientation = xlPageField .Position = 1 End With With ActiveSheet.PivotTables("数据透视表1").PivotFields("供应商") .subtotals=nosubtatal .Orientation = xlRowField .Position = 1 End With With ActiveSheet.PivotTables("数据透视表1").PivotFields("品种") .subtatals=nosubtatal .Orientation = xlRowField .Position = 2 End With With ActiveSheet.PivotTables("数据透视表1").PivotFields("单价(元)") .Orientation = xlRowField .Position = 3 End With ActiveSheet.PivotTables("数据透视表1").AddDataField ActiveSheet.PivotTables("数据透视表1" _ ).PivotFields("重量(KG)"), "求和项:重量(KG)", xlSum Columns("C:D").Select Selection.NumberFormatLocal = _ "_ * #,##0.00_ ;_ * -#,##0.00_ ;_ * ""-""??_ ;_ @_ " Columns("D:D").EntireColumn.AutoFit Columns("C:C").ColumnWidth = 8 ActiveWorkbook.ShowPivotTableFieldList = False End Sub |