Bonsoir,
que si quelqu'un avait un bout de code sur une étagère... : bin, j'ai construit l'étagère car effectivement, ça doit être fréquent
a essayer(valable pour 2 colonnes jointives, XL<2007):
Option Explicit
Const hauteur As Byte = 4 'hauteur des cellules fusionnées
Const zone As String = "A1:B21"
Sub trier_cell_fusionnées()
Dim lig As Long, nbre_lig As Long, etape As Long, col As Byte
Dim tablo_tri
Dim lig_src As Long, lig_cbl As Long
Dim cptr1 As Long, cptr2 As Long, cptr3 As Long, cptr4 As Long
Dim col_B As New Collection
Dim i, j, k As Long
Dim tmp0, tmp1
'---- INITIALISATION
col = Range(zone).Column
lig = Range(zone).Row
nbre_lig = Range(zone).Rows.Count
etape = ((nbre_lig - 1) / hauteur) - 1
ReDim tablo_tri(etape, 1)
'----- MEMORISATION des DONNEES
lig_src = lig
For cptr1 = 0 To etape
'mémorise valeur dans cellule fusionnée
tablo_tri(cptr1, 0) = Cells(lig_src, 1)
'mémorise ligne de la cellule
tablo_tri(cptr1, 1) = lig_src
lig_src = lig_src + hauteur
Next
'collecte les données dans la colonne à droite
For cptr2 = lig To nbre_lig - 1
col_B.Add Cells(cptr2, col + 1).Value
Next
'-----TRI
'trie dans l'ordre crissant valeurs et lignes dans cell fusionnées
For i = 0 To etape
j = i
For k = j + 1 To etape
If tablo_tri(k, 0) <= tablo_tri(j, 0) Then j = k
Next k
If i <> j Then
tmp0 = tablo_tri(j, 0)
tmp1 = tablo_tri(j, 1)
tablo_tri(j, 0) = tablo_tri(i, 0)
tablo_tri(j, 1) = tablo_tri(i, 1)
tablo_tri(i, 0) = tmp0
tablo_tri(i, 1) = tmp1
End If
Next i
'----- RESTITUTION
Application.ScreenUpdating = False
lig_cbl = lig
For cptr3 = 0 To etape
Cells(lig_cbl, col) = tablo_tri(cptr3, 0)
'cellule fusionnée
lig_src = tablo_tri(cptr3, 1)
For cptr4 = 0 To hauteur - 1
'cellule colonne de droite
Cells(lig_cbl + cptr4, col + 1) = col_B(lig_src + cptr4)
Next
lig_cbl = lig_cbl + hauteur
Next
'---- annulation du pointeur
Set col_B = Nothing
End Sub
Ci joint démo
http://www.cijoint.fr/cjlink.php?file=cj200905/cijvk2FwQb.xls
mais il ya peut-^tre + simple....
Cordialement, Michel