VBA problem with Applacation - definied in pivot table

Palucci

Banned user
Joined
Sep 15, 2021
Messages
138
Office Version
  1. 365
Platform
  1. Windows
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:

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
Run _
 

Excel Facts

Enter current date or time
Ctrl+: enters current time. Ctrl+; enters current date. Use Ctrl+: Ctrl+; Enter for current date & time.
Error at the start? You need to be more specific - exactly what row of code errors out?
 
Upvote 0

Forum statistics

Threads
1,215,024
Messages
6,122,729
Members
449,093
Latest member
Mnur

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