Error 13, incompatible types when creating a pivot table

travesseiro

New Member
Joined
Dec 16, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello everyone!

I looked everywhere but did not found anything that fixes this thing!

Im creating a pivot table as it follows:

VBA Code:
    Dim pvt As PivotCache
    Dim leftCorner As Range
    Dim rightCorner As Range
    Dim completeTable As String
    Dim destination As String

Set leftCorner = Cells(1, "B").End(xlDown)
    Set rightCorner = Cells(Rows.Count, "B").End(xlUp).Offset(, 5)
    completeTable = ActiveSheet.Name & "!" & Range(leftCorner, rightCorner).Address(ReferenceStyle:=xlR1C1)
    
    Worksheets("DataTreatment").Activate
    destination = ActiveSheet.Name & "!" & Range("B4").Address(ReferenceStyle:=xlR1C1)

    Set pvt = ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=completeTable, Version:=7). _
    CreatePivotTable(TableDestination:=destination, _
    TableName:="Tabela dinâmica2")

I keep getting error 13 at the "Set pvt" line, what is wrong here?

Thanks in advance!
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.

Forum statistics

Threads
1,215,046
Messages
6,122,852
Members
449,096
Latest member
Erald

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