pivot table help

Joined
Jul 6, 2006
Messages
7
Reaction score
0
hi, i am trying to write a vb code of a pivot table where certain data is taken from one worksheet and a various of ranges are used to create a pivot table for each set of data onto a new worksheet. The problem I am having is that if I used a variable range to create the pivot table, it gives an error

It works when I used only one set of data like

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"view_access!R8C1:R171C5").CreatePivotTable TableDestination:="", TableName _
:="PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
ActiveSheet.PivotTables("PivotTable1").AddFields RowFields:=Array("Year", _
"Quarter"), PageFields:="App"
ActiveSheet.PivotTables("PivotTable1").PivotFields("Size").Orientation = _
xlDataField
ActiveWorkbook.ShowPivotTableFieldList = False


but if I were to add the source data in a format to get multiple ranges in a loop like


ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"view_access!R" + index1 + "C1:R" + index2 + "C5").CreatePivotTable TableDestination:="", TableName _
:="PivotTable1", DefaultVersion:=xlPivotTableVersion10


I get a type mismatch error

where index1 and index2 are the row numbers of the different sets of data I want to chart.

Any ideas on how to fix this error would be appreciated, thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top