Grouping the specific rows with text in a pivot table (VBA)

mihaipal

New Member
Joined
Jan 25, 2018
Messages
1
Hello everyone !

I need help for grouping the specific rows with text in a pivot table (with VBA).

So, I have a column with the countries codes resulting in a pivot table: AT, GB, PL, PT , FR , DE
I whant that automaticly the cells with AT , GB and PT to be grouped in a group called Europe, every time when the pivot table is changed regrdles their possition.

Thank you very much for help !
Best regards,

Mihai



Selection.Group
Range("A12").Select
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale2").PivotItems("Groupe2").Caption = "EUROPE"
Range("A3,A4,A5,A6,A9,A10,A11,A14,A15").Select
Range("A15").Activate



Sheets("NouveauWF").Select
Cells.Select
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
"NouveauWF!R1C1:R1048576C93", Version:=xlPivotTableVersion15). _
CreatePivotTable TableDestination:="SyntheseNouveauWF2!R1:R1048576", _
TableName:="Tableau croisé dynamique3", DefaultVersion:= _
xlPivotTableVersion15
Sheets("SyntheseNouveauWF2").Select
Cells(1, 1).Select
ActiveWorkbook.ShowPivotTableFieldList = True
Range("A2").Select
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotCache.Refresh
With ActiveSheet.PivotTables("Tableau croisé dynamique3")
.InGridDropZones = True
.RowAxisLayout xlTabularRow
End With
ActiveSheet.PivotTables("Tableau croisé dynamique3").AddDataField ActiveSheet. _
PivotTables("Tableau croisé dynamique3").PivotFields("Num demande"), _
"Nombre de Num demande", xlCount
With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Niv vieillissement")
.Orientation = xlColumnField
.Position = 1
End With
With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale")
.Orientation = xlRowField
.Position = 1
End With
Range("A3").Select
With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale")
.LayoutSubtotalLocation = xlAtBottom
.LayoutForm = xlOutline
.LayoutCompactRow = True
End With
Range("A7,A10").Select
Range("A10").Activate
Selection.Group
Range("A7").Select
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale2").PivotItems("Groupe1").Caption = "UET SUD"
Range("A12,A13").Select
Range("A13").Activate
Selection.Group
Range("A12").Select
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale2").PivotItems("Groupe2").Caption = "EUROPE"
Range("A3,A4,A5,A6,A9,A10,A11,A14,A15").Select
Range("A15").Activate
Selection.Group
Range("A3").Select
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale2").PivotItems("Groupe3").Caption = "UET NORD"
Range("A4").Select
With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale2")
.PivotItems("(blank)").Visible = False
End With
Range("A3").Select
With ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale2")
.LayoutSubtotalLocation = xlAtBottom
.LayoutForm = xlOutline
.LayoutCompactRow = True
End With
Range("A3").Select
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale2").PivotItems("UET NORD").ShowDetail = False
Range("A7").Select
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale2").PivotItems("UET RSR EUROPE").ShowDetail = False
Range("A4").Select
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Pays Filiale2").PivotItems("UET SUD").ShowDetail = False
ActiveSheet.PivotTables("Tableau croisé dynamique3").PivotFields( _
"Niv vieillissement").AutoSort xlDescending, "Niv vieillissement"
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.

Forum statistics

Threads
1,224,827
Messages
6,181,200
Members
453,022
Latest member
RobertV1609

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