I accidentally inserted CALCULATED FIELD into my pivot row instead if inserting CALCULATED FIELD in the data area. Have a month "Formula1" made the pivot look bad and it was cumbersome to HIDE that item on each pivot copy. How do I remove or delete it from the pivot's cache memory?
I didn't find any direct answer with a quick search, but I did figure something out, and thus I'm posting the answer here.
I tried a macro from the following website to clear the cache, but it didn't quite work (it works when the data source used to actually have an item, but not for items inserted using the INSERT CALCULATED FIELD option).
http://www.contextures.com/xlPivot04.html
| Code: |
Sub DeleteMissingItems2002All()
'prevents unused items in non-OLAP PivotTables
Dim pt As PivotTable
Dim ws As Worksheet
Dim pc As PivotCache
'change the settings
For Each ws In ActiveWorkbook.Worksheets
For Each pt In ws.PivotTables
pt.PivotCache.MissingItemsLimit = xlMissingItemsNone
Next pt
Next ws
'refresh all the pivot caches
For Each pc In ActiveWorkbook.PivotCaches
On Error Resume Next
pc.Refresh
Next pc
End Sub
|
So tried using whatever command I could think of and found out that the PIVOTITEM property worked. The field I had inserted was in cell B16, so I used the following code to delete it... then ran the above code to clear the cache.
| Code: |
Sub RemoveItem()
Range("B16").PivotItem.Delete
End Sub
|
It worked.
--Paul