meetdudhia
New Member
- Joined
- Jul 8, 2011
- Messages
- 14
Sub pivot2()
Dim PTCache As PivotCache
Dim pt As PivotTable
Dim XYZ As String
'On Error Resume Next
XYZ2 = Sheets("Action").Range("W1")
XYZ1 = Sheets("Action").Range("W2")
XYZ = Sheets("Action").Range("W3")
XYZ4 = Sheets("Action").Range("W6")
'create the cache
Set PTCache = ActiveWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=Range("A1").CurrentRegion)
'Add new sheet
Worksheets.Add
'create the pivot table
Set pt = ActiveSheet.PivotTables.Add( _
PivotCache:=PTCache, _
TableDestination:=Range("A3"), _
TableName:="XYZ")
With ActiveSheet.PivotTables("XYZ").PivotFields(XYZ2)
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("XYZ").PivotFields(XYZ1)
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("XYZ").PivotFields(XYZ)
.Orientation = xlDataField
.Position = 1
.NumberFormat = "#0.0%"
.Calculation = "XYZ4"
End With
End Sub
Question: In calculation field I have reference (.Calculation = "XYZ4"), but VBA is giving me error, can any one tell me how to reference it so it can work with my list box.
I really appreciate any help.
thank you
Dim PTCache As PivotCache
Dim pt As PivotTable
Dim XYZ As String
'On Error Resume Next
XYZ2 = Sheets("Action").Range("W1")
XYZ1 = Sheets("Action").Range("W2")
XYZ = Sheets("Action").Range("W3")
XYZ4 = Sheets("Action").Range("W6")
'create the cache
Set PTCache = ActiveWorkbook.PivotCaches.Create( _
SourceType:=xlDatabase, _
SourceData:=Range("A1").CurrentRegion)
'Add new sheet
Worksheets.Add
'create the pivot table
Set pt = ActiveSheet.PivotTables.Add( _
PivotCache:=PTCache, _
TableDestination:=Range("A3"), _
TableName:="XYZ")
With ActiveSheet.PivotTables("XYZ").PivotFields(XYZ2)
.Orientation = xlRowField
.Position = 1
End With
With ActiveSheet.PivotTables("XYZ").PivotFields(XYZ1)
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("XYZ").PivotFields(XYZ)
.Orientation = xlDataField
.Position = 1
.NumberFormat = "#0.0%"
.Calculation = "XYZ4"
End With
End Sub
Question: In calculation field I have reference (.Calculation = "XYZ4"), but VBA is giving me error, can any one tell me how to reference it so it can work with my list box.
I really appreciate any help.
thank you