View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
[email protected] BenKoeppen@gmail.com is offline
external usenet poster
 
Posts: 1
Default 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