Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Excel PivotTables
#8
Recorded:
Code:
Copy      Help
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2008.11.21 by G
'

'
    ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
        "Sheet1!R1C1:R6C3").CreatePivotTable TableDestination:="", TableName:= _
        "PivotTable2", DefaultVersion:=xlPivotTableVersion10
    ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
    ActiveSheet.Cells(3, 1).Select
    Exit Sub
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("name")
        .Orientation = xlRowField
        .Position = 1
    End With
    With ActiveSheet.PivotTables("PivotTable2").PivotFields("date")
        .Orientation = xlColumnField
        .Position = 1
    End With
    ActiveSheet.PivotTables("PivotTable2").AddDataField ActiveSheet.PivotTables( _
        "PivotTable2").PivotFields("score"), "Sum of score", xlSum
End Sub

Converted:
Macro
Code:
Copy      Help
;/exe 1
typelib Excel
ExcelSheet es.Init
Excel.Application a=es.ws.Application

a.ActiveWorkbook.PivotCaches.Add(xlDatabase, "Sheet1!R1C1:R6C3").CreatePivotTable("", "PivotTable2", @, xlPivotTableVersion10)
Excel.Worksheet ws=a.ActiveSheet
Range r=ws.Cells.Item(3, 1)
ws.PivotTableWizard(@ @ r)
r.Select
Excel.PivotTable t=ws.PivotTables("PivotTable2")
t.PivotFields("name").Orientation = xlRowField
t.PivotFields("name").Position = 1
t.PivotFields("date").Orientation = xlColumnField
t.PivotFields("date").Position = 1
t.AddDataField(t.PivotFields("score"), "Sum of score", xlSum)


Messages In This Thread

Forum Jump:


Users browsing this thread: 4 Guest(s)