I have a problem creating a pivot table from a tab " Kredyty" , I would like to create a table with two filters and two value fields. However, I have such an error at the start ; Run- Time error '1004' Application - definied error"
My code:
Run _
My code:
Rich (BB code):
Dim tbName As String
Dim lr1 As Long, ptver1 As Long
Dim tbName1 As String
Set sh_s = wbMe.Sheets("kredyty")
lr1 = sh_s.Range(Rows.Count, 1).End(xlUp).Row
ptver1 = 6
tbName1 = "Tabela przestawna"
Sheets.Add after:=Sheets(Sheets.Count)
Set sh_d = ActiveSheet
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, _
SourceData:=sh_s.Name & "!R1C1:R" & lr & "C12", Version:=ptver).CreatePivotTable _
TableDestination:=sh_d.Name & "!R3C1", TableName:=tbName1, _
DefaultVersion:=ptver1
With sh_d.PivotTables(tbName)
.PivotFields ("CRD_RWG")
.Orientation = xlRowField
.Position = 1
With sh_d.PivotTables(tbName)
.PivotFields ("NEW_DEFAULT")
.Orientation = xlRowField
.Position = 2
End With
.AddDataField .PivotFields("CRD_EKSP_PIER_DC_FIN"), "Suma z Ekspozycji", xlSum
.AddDataField .PivotFields("CRD_KOR_DC_FIN"), "Suma z Korekty", xlSum
End With