ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   pivot cache in VBA (https://www.excelbanter.com/excel-programming/397909-pivot-cache-vba.html)

[email protected]

pivot cache in VBA
 
Hi,
I want to create a pivot cache using VBA. If I write

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase, SourceData:=
_
"A1:AC3167").CreatePivotTable TableDestination:="", _
TableName:="myPivotTable",
DefaultVersion:=xlPivotTableVersion10

it works. But if I write

myLastRow = Range("A1").End(xlDown).Row
myLastColumn = Range("A1").End(xlToRight).column
myRange = Range(Cells(1, 1), Cells(myLastRow, myLastColumn))

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatab ase,
SourceData:= _
myRange).CreatePivotTable TableDestination:="", _
TableName:="myPivotTable",
DefaultVersion:=xlPivotTableVersion10

I get an "Type Mismatch" error. I tried various structures from for
the myRange, but none worked.

Any help apreciated.

Ben



All times are GMT +1. The time now is 06:24 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com