Run-time error 1004 when creating a pivot table using VBA after Windows Security Patch update

Johns, Lewis 20 Reputation points
2025-06-25T17:36:24.1233333+00:00

After updating the Windows Security Patch on 06/23/2025, Macros stopped working, and the following error is encountered: "Run-time error 1004: The PivotTable field name is not valid."

During debugging, the highlighted code is:

'pivot table data source range will need to be updated if additional columns are added. One cell before "Extract" cell - Albers 12/25/24

ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
    "Cleansed data!R2C2:R" & lastrow & "C122").CreatePivotTable TableDestination:=Range("A3"), TableName:="PivotTable2"

ActiveSheet.PivotTables("PivotTable2").SmallGrid = False

ActiveSheet.PivotTables("PivotTable2").PivotSelect "", xlDataAndLabel

ActiveSheet.PivotTables("PivotTable2").Format xlReport2

ActiveSheet.PivotTables("PivotTable2").AddFields RowFields:=Array("PY", _
    "Benefit_State_Num"), ColumnFields:= _
    "Data"

This code was functioning correctly before the security patch was applied. After triple-checking, no changes have been found in the code. Could the security update be the cause of this issue?

Microsoft 365 and Office Excel For business Windows
{count} votes

Accepted answer
  1. Dora-T 1,490 Reputation points Microsoft External Staff Moderator
    2025-06-26T04:41:40.33+00:00

    Hi @Johns, Lewis

    Welcome to the Microsoft Q&A Forum. 

    Based on the information you’ve provided, it seems the macro code itself may still be valid. However, the error you're encountering, "Run-time error 1004: The PivotTable field name is not valid", is commonly caused by issues in the source data. Please review the structure of your data, such as: 

    • Missing or blank column headers. 
    • Merged cells in the header row. 
    • Field names in the macro not matching the actual column headers in the data. 

    At this time, there is no official confirmation from Microsoft that the Windows Security Patch released on June 23, 2025, directly causes this issue. However, I also found a related issue in the Microsoft Community that appears to be caused by recent Excel updates. While it's not exactly the same as yours, you might find it helpful to read through: Run-time Error 1004 "The PivotTable filed name is not valid..." - Microsoft Community 

    If the issue persists after checking the data structure, feel free to share more details or a sample of your workbook, and I’d be happy to assist further.  I'm looking forward to your update.


    If the answer is partially helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".        

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.