Unable to get the pivottables property of the worksheet blablabla

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
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce

Forum statistics

Threads
1,215,107
Messages
6,123,126
Members
449,097
Latest member
mlckr

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top