SeanDamnit
Board Regular
- Joined
- Mar 13, 2011
- Messages
- 151
Hello Internet,
I have a macro that combines a few reports, does some calculation on the data, and sums everything up in a pivot table. The process works great when my combined raw data has ~36000 line items. However if I expand my reporting range and end up north of 60000 line items, I get a "Type Mismatch" error when attempting to set the PivotCache. See code snippet below:
Why would this work just fine with 36k lines, but not with 60k lines? Pretty sure I'm properly declaring my variables here...any advice?
I have a macro that combines a few reports, does some calculation on the data, and sums everything up in a pivot table. The process works great when my combined raw data has ~36000 line items. However if I expand my reporting range and end up north of 60000 line items, I get a "Type Mismatch" error when attempting to set the PivotCache. See code snippet below:
Code:
Sub AgedInvReport()
Dim newBook As Workbook
Dim wbData As Worksheet
Dim wbSum As Worksheet
Dim PRange As Range
Dim PTCache As PivotCache
Dim pt1 As PivotTable
Dim pt2 As PivotTable
Dim LRData As Long
'SNIP SNIP'
'===========Setup Pivot Table==========='
Workbooks("Skynet.xla").Sheets("Aged Inventory").Copy Before:=wbData
Set wbSum = newBook.Sheets("Aged Inventory")
LRData = wbData.Cells(wbData.Rows.Count, colInvSku).End(xlUp).Row
Set PRange = wbData.Cells(1, 1).Resize(LRData, 19)
With wbSum
.Range(.Columns(14), .Columns.End(xlToRight)).EntireColumn.Hidden = True
Set PTCache = .Parent.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=PRange, Version:=xlPivotTableVersion12) 'getting the error here
Set pt1 = PTCache.CreatePivotTable(TableDestination:=.Cells(11, 2), TableName:="ByLocation", DefaultVersion:=xlPivotTableVersion12)
Set pt2 = PTCache.CreatePivotTable(TableDestination:=.Cells(11, 7), TableName:="BySKU", DefaultVersion:=xlPivotTableVersion12)
'SNIP SNIP'
Why would this work just fine with 36k lines, but not with 60k lines? Pretty sure I'm properly declaring my variables here...any advice?