Hi,
I was wondering how can I group pivot items based on the name ?, e.g. I want to group all the pivot items that are not named US or CA or BR , I did a little research on the forum and I found a code that I can adapt but is not very elegant , so I'm wondering if you guys have a better suggestion.
Any help will be much appreciated
I was wondering how can I group pivot items based on the name ?, e.g. I want to group all the pivot items that are not named US or CA or BR , I did a little research on the forum and I found a code that I can adapt but is not very elegant , so I'm wondering if you guys have a better suggestion.
Any help will be much appreciated
Code:
Sub test()
Dim i As Integer
Dim cell1 As String
Dim cell2 As String
Dim rng As Range
With ActiveSheet.PivotTables("[YourPivotTableName]").PivotFields_("[YourFieldName]")
For i = 1 To .PivotItems.Count
If .PivotItems(i).Name Like "[YourItemName]" Then
.PivotItems(i).LabelRange.Select
cell1 = ActiveCell.Address
ElseIf .PivotItems(i).Name Like "[YourItemName]" Then
.PivotItems(i).LabelRange.Select
cell2 = ActiveCell.Address
Else
End If
Next i
End With
Set rng = Range(cell1, cell2)
Selection.Group
End Sub