1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| Sub test()
'Crée des groupes en fonction de deux intervales
Dim t() As Variant, i As Byte, c As Range, p As Range, pi As PivotItem, t2 As String
'déclaration des intervales
t = Array(0, 0.25, 0.5, 0.75, 1)
With Feuil5.PivotTables("Tableau croisé dynamique9")
'trie des valeurs numérique plus petit au plus grand
.PivotFields("[Machine_ISL].[avanc.].[avanc.]").AutoSort xlAscending, "[Machine_ISL].[avanc.].[avanc.]"
'commencement des 5 boucles
i = 0
For Each c In .PivotFields("[Machine_ISL].[avanc.].[avanc.]").DataRange
If c = t(i) Then If p Is Nothing Then Set p = c Else Set p = Union(p, c)
Next c
'écriture en mémoire de l'intervale des groupes
If Not p Is Nothing Then t2 = t(i) & ";": If p.Count > 1 Then p.Group
Set p = Nothing
For i = 1 To 3
For Each c In .PivotFields("[Machine_ISL].[avanc.].[avanc.]").DataRange
If c > t(i - 1) And c <= t(i) Then If p Is Nothing Then Set p = c Else Set p = Union(p, c)
Next c
'écriture en mémoire de l'intervale des groupes
If Not p Is Nothing Then t2 = t2 & t(i - 1) & " à " & t(i) & ";": If p.Count > 1 Then p.Group
Set p = Nothing
Next i
i = 4
For Each c In .PivotFields("[Machine_ISL].[avanc.].[avanc.]").DataRange
If c > t(i - 1) And c < t(i) Then If p Is Nothing Then Set p = c Else Set p = Union(p, c)
Next c
'écriture en mémoire de l'intervale des groupes
If Not p Is Nothing Then t2 = t2 & t(i - 1) & " à " & t(i) & ";": If p.Count > 1 Then p.Group
Set p = Nothing
i = 4
For Each c In .PivotFields("[Machine_ISL].[avanc.].[avanc.]").DataRange
If c = t(i) Then If p Is Nothing Then Set p = c Else Set p = Union(p, c)
Next c
'écriture en mémoire de l'intervale des groupes
If Not p Is Nothing Then t2 = t2 & t(i) & (";VR;VR(FC.GW;"): If p.Count > 1 Then p.Group
Set p = Nothing
With .PivotFields(.PivotFields.Count)
i = 0
'boucle renomme les groupes avec nom intervalle
For Each pi In .PivotItems
If pi.Visible Then pi.Name = Split(t2, ";")(i): i = i + 1
Next pi
End With
End With
End Sub |
Partager