themeltdown
New Member
- Joined
- Nov 14, 2013
- Messages
- 1
Hi,
I searched on all forum and I don't find the solution. I have error 1004, Unable to get the... on ligne:
With PT.PivotFields("Product"). Then I tried a recorded macro... But it doesn't work too...
I don't know why.
Please answer if you have any suggestion.
This is my code:
Best,
themeltdown
Dim PTCache As PivotCache
Dim PT As PivotTable
Dim PRange As Range
Dim FinalRow As Long
Dim FinalCol As Long
Dim WKS As Worksheet
Set WKS = wb1.Worksheets(3)
' Delete any prior pivot tables
For Each PT In WKS.PivotTables
PT.TableRange2.Clear
Next PT
' Define inpout aera
'Define input area and set up a Pivot Cache
FinalRow = wb1.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
FinalCol = wb1.Worksheets(1).Cells(1, Columns.Count).End(xlToLeft).Column
Set PRange = wb1.Worksheets(1).Cells(1, 1).Resize(FinalRow, FinalCol)
Set PTCache = wb1.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:=PRange)
'After defining the pivot cache, use the CreatePivotTable method to create a blank pivot
'table based on the defined pivot cache:
Set PT = PTCache.CreatePivotTable(TableDestination:=WKS.Cells(1, 1), _
TableName:="PivotTable1")
PT.ManualUpdate = True
PT.AddFields RowFields:=Array("Type", "Region/Country", "Country"), ColumnFields:="Data"
With PT.PivotFields("Unit price")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0"
.Position = 1
End With
With PT.PivotFields("Nombre of Unit")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0"
.Position = 2
End With
PT.CalculatedFields.Add Name:="Product", Formula:="=Unit Price*Nombre of Unit"
On Error Resume Next
With PT.PivotFields("Product")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0"
.Position = 3
.Name = "Pro"
End With
I searched on all forum and I don't find the solution. I have error 1004, Unable to get the... on ligne:
With PT.PivotFields("Product"). Then I tried a recorded macro... But it doesn't work too...
I don't know why.
Please answer if you have any suggestion.
This is my code:
Best,
themeltdown
Dim PTCache As PivotCache
Dim PT As PivotTable
Dim PRange As Range
Dim FinalRow As Long
Dim FinalCol As Long
Dim WKS As Worksheet
Set WKS = wb1.Worksheets(3)
' Delete any prior pivot tables
For Each PT In WKS.PivotTables
PT.TableRange2.Clear
Next PT
' Define inpout aera
'Define input area and set up a Pivot Cache
FinalRow = wb1.Worksheets(1).Cells(Rows.Count, 1).End(xlUp).Row
FinalCol = wb1.Worksheets(1).Cells(1, Columns.Count).End(xlToLeft).Column
Set PRange = wb1.Worksheets(1).Cells(1, 1).Resize(FinalRow, FinalCol)
Set PTCache = wb1.PivotCaches.Add(SourceType:=xlDatabase, _
SourceData:=PRange)
'After defining the pivot cache, use the CreatePivotTable method to create a blank pivot
'table based on the defined pivot cache:
Set PT = PTCache.CreatePivotTable(TableDestination:=WKS.Cells(1, 1), _
TableName:="PivotTable1")
PT.ManualUpdate = True
PT.AddFields RowFields:=Array("Type", "Region/Country", "Country"), ColumnFields:="Data"
With PT.PivotFields("Unit price")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0"
.Position = 1
End With
With PT.PivotFields("Nombre of Unit")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0"
.Position = 2
End With
PT.CalculatedFields.Add Name:="Product", Formula:="=Unit Price*Nombre of Unit"
On Error Resume Next
With PT.PivotFields("Product")
.Orientation = xlDataField
.Function = xlSum
.NumberFormat = "#,##0"
.Position = 3
.Name = "Pro"
End With