user3716558
user3716558

Reputation: 11

VBA Pivot Table Datafield Orientation Needs to be Flipped

My current code causes my data fields to return as rows rather than columnar. My goal is to make make the data fields have the columnar orientation.

Set objtable = Sheets(Worksheets.Count).PivotTableWizard

    Set objfield = objtable.PivotFields("Asset ID")
        objfield.Orientation = xlRowField

    Set objfield = objtable.PivotFields("Date")
        objfield.Orientation = xlColumnField

    Set objfield = objtable.PivotFields("Landmark")
        objfield.Orientation = xlPageField

    Set objfield = objtable.PivotFields("Charge")
        objfield.Orientation = xlDataField
        objfield.Function = xlSum

    Set objfield = objtable.PivotFields("Arrival Date")
        objfield.Orientation = xlDataField
        objfield.Function = xlMinenter code here

Upvotes: 1

Views: 1337

Answers (1)

Varalakshmi Munuswamy
Varalakshmi Munuswamy

Reputation: 11

it depends on the Pivot table version. The following code can help solve your issue, when you create the pivot use the version 12 that is xlPivotTableVersion12.

DesWorkBk.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=sourcedataStr, Version:=xlPivotTableVersion12).CreatePivotTable _
       TableDestination:=wsPvtTbl.Range("A1"), TableName:="PivotTable2"

Upvotes: 1

Related Questions