Runtime error "1004" Unable to set the Position property of the PivotItem Class

kht0307

New Member
Joined
Jul 19, 2024
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi, I have the following code, that results in the above error when it hits the highlighted line:

For Each WS In ActiveWorkbook.Worksheets
WS.Select
If ActiveSheet.Name Like "Pivot*" And ActiveSheet.Name <> "Pivot Current month" Then
With ActiveSheet.PivotTables("PivotTable1").PivotFields("Period")
.PivotItems("Flash").Position = .PivotItems.Count
End With
End If
Next WS


Can anyone please advise me as to what is going wrong here.
 

Excel Facts

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Hi, I have the following code, that results in the above error when it hits the highlighted line:

For Each WS In ActiveWorkbook.Worksheets
WS.Select
If ActiveSheet.Name Like "Pivot*" And ActiveSheet.Name <> "Pivot Current month" Then
With ActiveSheet.PivotTables("PivotTable").PivotFields("Period")
.PivotItems("Flash").Position = .PivotItems.Count
End With
End If
Next WS


Can anyone please advise me as to what is going wrong here.
 
Upvote 0
That would indicate that the Item "Flash" does not exist in the PivotField "Period". This seem highly likely, since I would expect the field Period to contain dates.
 
Upvote 0
Thanks Alex, it does exist in the PivotField "Period", see below screenshot:

1721394661656.png
 
Upvote 0
Can you type Flash into a cell eg d5 and then in e5 put =D5= and point to the cell that contains Flash ?
or simply ="Flash" = the cell that contains Flash
 
Upvote 0
Yes, see below:

1721395376850.png


So in cell B29 I have typed = B26 and the result is Flash
 
Upvote 0
That won't show you if its exactly Flash so either
="Flash" = B26
or =Len(B26)
if the first one returns false definitely do the 2nd one too
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,287
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top