Chirag R Raval
Member
Dear Sirs,
i have below code for generate pivot table.
can we reference in code "Filed Number" OR "Column Number" instead of "Field Name"
when generating pivot table ?
because many time, Heading mostly change of particular column like
""PivotTable1").PivotFields("ORD" & Chr(10) & "VAL"), " some time Header is "Order Value" so there are macro stop at that point, i must have change header in sheet as per code.
There are some solution there that we can reference direct column number instead of Field Name?
Regards,
Chirag Raval
i have below code for generate pivot table.
Code:
Set PCache = ActiveWorkbook.PivotCaches.Create(SourceType:=1, SourceData:=Range("A1").CurrentRegion.address)
Worksheets.add
ActiveSheet.name = "Pivot"
ActiveWindow.DisplayGridlines = False
Set pt = ActiveSheet.PivotTables.add(PivotCache:=PCache, TableDestination:=Range("A1"), TableName:="PivotTable1")
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable1").PivotFields("AR")
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("CHNL")
.Orientation = xlRowField
.Position = 2
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("BUY")
.Orientation = xlRowField
.Position = 3
End With
With ActiveSheet.PivotTables("PivotTable1").PivotFields("PARTY")
.Orientation = xlRowField
.Position = 4
End With
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("CONF" & Chr(10) & "UNT"), "Sum of CONF" & Chr(10) & "UNT", xlSum
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("CONF" & Chr(10) & "QTY"), "Sum of CONF" & Chr(10) & "QTY", xlSum
ActiveSheet.PivotTables("PivotTable1").AddDataField ActiveSheet.PivotTables( _
"PivotTable1").PivotFields("ORD" & Chr(10) & "VAL"), "Sum of ORD" & Chr(10) & "VAL", xlSum
ActiveSheet.PivotTables("PivotTable1").PivotFields("AR").LayoutForm = xlTabular
ActiveSheet.PivotTables("PivotTable1").PivotFields("CHNL").LayoutForm = _
xlTabular
ActiveSheet.PivotTables("PivotTable1").PivotFields("BUY").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable1").PivotFields("BUY").LayoutForm = _
xlTabular
ActiveSheet.PivotTables("PivotTable1").PivotFields("PARTY").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable1").PivotFields("PARTY").LayoutForm = _
xlTabular
ActiveSheet.PivotTables("PivotTable1").PivotFields("PARTY").Subtotals = Array( _
False, False, False, False, False, False, False, False, False, False, False, False)
ActiveSheet.PivotTables("PivotTable1").PivotFields("PARTY").LayoutForm = _
xlTabular
ActiveSheet.PivotTables("PivotTable1").PivotSelect "", xlDataAndLabel, True
'ActiveSheet.PivotTables("PivotTable1").TableRange1.Copy
can we reference in code "Filed Number" OR "Column Number" instead of "Field Name"
when generating pivot table ?
because many time, Heading mostly change of particular column like
""PivotTable1").PivotFields("ORD" & Chr(10) & "VAL"), " some time Header is "Order Value" so there are macro stop at that point, i must have change header in sheet as per code.
There are some solution there that we can reference direct column number instead of Field Name?
Regards,
Chirag Raval