Using Excel 2010.
A pivot table process that works when there are <= 65,536 rows in the
SourceData range fails as soon as the row count goes >65,536. Debugger
returns a "Type Mismatch" error at the Set PTCache = portion of the
script highlighted below. Included are two methods I've tried for the
SourceData, neither works.
Is there a way to make this work for more rows?
Below is the section of script with two approaches I've tried. Both work when <65,537 and both fail when >. Thanks -- KR
Public Sub SalesContactReport()
Dim pt As PivotTable
Dim strField As String
Dim WSD As Worksheet
Dim PTOutput As Worksheet
Dim PTCache As PivotCache
Dim PRange As Range
Dim pi As PivotItem
Dim finalRow As Long
Dim finalCol As Long
'Set pivot table worksheet as active
Sheets("Table").Activate
' Initialize worksheets
Set WSD = ActiveWorkbook.Worksheets("Detail")
Set PTOutput = ActiveWorkbook.Worksheets("Table")
*******************************************
This was my 1st approach
*******************************************
' Find the last row with data
finalRow = WSD.Cells(Application.Rows.Count, 1).End(xlUp).Row
' Find the last column with data
finalCol = WSD.Cells(1,
Application.Columns.Count).End(xlToLeft).Column
' Find the range of the data
Set PRange = WSD.Cells(1, 1).Resize(finalRow, finalCol)
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:=PRange) << Type mismatch error.
*******************************************
This was my 2nd approach
*******************************************
Set PTCache = ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase,
SourceData:= _
Worksheets("Detail").Range("A1").CurrentRegion) << Type mismatch error
.
.
.
.
.
End Sub