Mackeral
Board Regular
- Joined
- Mar 7, 2015
- Messages
- 249
- Office Version
- 365
- Platform
- Windows
This is the code I'm using:
It works when I add data to DATA, and I can run it any number of times then.
But when I shorten the amount of data it dies saying
But I haven't changed any field names, only deleted some of the data
to check that the routine is working correctly.
Thanks for any help.
Code:
Sub a_Recalc_Pivot_Table()
' Macro to recalculate Pivot Table.
' 2/7/12 Modified. WML '
' 7/29/19 Copied from "Offfice Development Center". WML
Call Initialize_Globals
Data.Activate
'Determine the data range you want to pivot
Rng = Make_Range(Data_Row, 1, -1, -1, Data)
SrcData = "Data" & "!" & Range(Rng).ADDRESS(ReferenceStyle:=xlR1C1)
DataArea = "Data!R2C1:R" & Selection.Rows.Count & "C" & Selection.Columns.Count
Sheets("Pivot Table").PivotTables("PivotTable3").ChangePivotCache ActiveWorkbook. _
PivotCaches.Create(SourceType:=xlDatabase, SourceData:=DataArea, _
Version:=xlPivotTableVersion14)
PIVOT.Activate
End Sub ' a_Recalc_Pivot_Table
It works when I add data to DATA, and I can run it any number of times then.
But when I shorten the amount of data it dies saying
Code:
Run-Time Error '-2147024809 (80070057)
The PivotTable field name is not valid. To creat a PivotTable report,
you must use data that is organized as a list with labeled columns. If
you are changing the name of the PivotTable Field, you must type
a new name for the field.
But I haven't changed any field names, only deleted some of the data
to check that the routine is working correctly.
Thanks for any help.