I have an existing workbook that has a bunch of Pivottables based on the same Pivotcache. I made the mistake of not setting it to use enough rows. I am trying to write a macro that changes the pivotcache to use all rows. I receive an error on the red line below. Error 1004 Application-defined or object-defined error.
I am using Excel 2003. Can anybody tell me how to fix this or how to do it manually (short of recreating all the pivot tables)?
I am using Excel 2003. Can anybody tell me how to fix this or how to do it manually (short of recreating all the pivot tables)?
Code:
Sub PivotTablesAllRows()
Dim PCache As PivotCache
Dim PCaches As PivotCaches
Dim lngRowStart As Long
Dim strRowStart As String
Dim strColEnd As String
Set PCaches = ActiveWorkbook.PivotCaches
For Each PCache In PCaches
lngRowStart = InStr(1, PCache.SourceData, ":R") + 1
strRowStart = Left(PCache.SourceData, lngRowStart)
strColEnd = Right(PCache.SourceData, 1 + Len(PCache.SourceData)_
- InStr(lngRowStart, PCache.SourceData, "C"))
[red]PCache.SourceData = strRowStart & "65536" & strColEnd[/red]
Next PCache
End Sub