I wrote a simple macro with which to filter a pivot table with the items that I have selected.
When the items in the Pivot Field are not numbers, it works perfectly.
But when the items are only numbers, it just doesn't work and I don't understand why and how to make it work.
Any ideas or tips ?
Thank you in advance!
- Sub FOCUS()
- On Error Resume Next
- Application.ScreenUpdating = False
- Dim sField As String
- Dim sPivot As String
- Dim pt As PivotTable
- Dim pItem As PivotItem
- Dim rRange
- sPivot = ActiveCell.PivotTable.Name
- sField = ActiveCell.PivotField.Name
- Set pt = ActiveSheet.PivotTables(sPivot)
- rRange = Range("XFD1:XFD50")
- For Each pItem In pt.PivotFields(sField).PivotItems
- If IsError(Application.Match(pItem, rRange, False)) Then
- pItem.Visible = False
- End If
- Next pItem
- Application.ScreenUpdating = True
- End Sub