XL 2016 Regrouper cellule selon critere commun

bibbip35

XLDnaute Occasionnel
Bonjour à tous

Je cherche a faire une macro. afin de regrouper plusieurs cellule en une ( Valeurs mis a la ligne )
selon un critère commun
J'ai bien pensé en cancaner les cellules , mais au vue du nombre de ligne a traiter ca serait une Opération
longue et fastidieuse

Auriez-vous une idée commun procédé ?

Merci à tous pour votre aide

Bibbip
 

Pièces jointes

  • Test Regroupement Bibbip.xlsx
    10.1 KB · Affichages: 43

job75

XLDnaute Barbatruc
Bonjour bibibip35, djidji59430,

Le code de la feuille "Résultat" (clic droit sur l'onglet et Visualiser le code) :
Code:
Private Sub Worksheet_Activate()
Dim L#, tablo, d As Object, i&, x$, a, b, c$()
With Feuil1 'CodeName de la feuille
    .Columns(2).AutoFit 'ajustement largeur
    L = .Columns(2).ColumnWidth
    tablo = .[A1].CurrentRegion.Resize(, 2) 'matrice, plus rapide
End With
Set d = CreateObject("Scripting.Dictionary")
For i = 1 To UBound(tablo)
    x = tablo(i, 1)
    d(x) = d(x) & IIf(d.exists(x), vbLf, "") & tablo(i, 2)
Next
Application.ScreenUpdating = False
If FilterMode Then ShowAllData 'si la feuille est filtrée
Cells.Delete 'RAZ
Columns(2).ColumnWidth = 66 'à adapter
'---transposition---
a = d.keys: b = d.items
ReDim c(UBound(a), 1) 'base 0
For i = 0 To UBound(c): c(i, 0) = a(i): c(i, 1) = b(i): Next
'---restitution---
Columns(2).WrapText = True 'renvoi à la ligne
Columns(2).ColumnWidth = L
[A1].Resize(i, 2) = c
End Sub
Fichier joint.

A+
 

Pièces jointes

  • Test Regroupement Bibbip(1).xlsm
    22.8 KB · Affichages: 34

BOISGONTIER

XLDnaute Barbatruc
Repose en paix
Bonjour,

Code:
Private Sub Worksheet_Activate()
  Set f = Sheets("Fichier de Base")
  Set d1 = CreateObject("Scripting.Dictionary")
  Tbl = f.Range("a1:b" & f.[a65000].End(xlUp).Row).Value
  For i = 1 To UBound(Tbl)
  d1(Tbl(i, 1)) = d1(Tbl(i, 1)) & Tbl(i, 2) & vbCrLf
  Next i
  [A2].Resize(d1.Count) = Application.Transpose(d1.keys)
  [b2].Resize(d1.Count) = Application.Transpose(d1.items)
End Sub
 

Pièces jointes

  • Copie de Test Regroupement Bibbip.xls
    38.5 KB · Affichages: 38
Dernière édition:

job75

XLDnaute Barbatruc
Bonjour bibbip35, JB, ke forum,

Chez moi sur Win 10 - Excel 2013 avec la macro de JB il y a un bug sur :
Code:
  [b2].Resize(d1.Count) = Application.Transpose(d1.items)
et je ne comprends pas pourquoi !

C'est d'ailleurs pour cette raison que je fais une transposition par boucle.

Bonne journée.
 

BOISGONTIER

XLDnaute Barbatruc
Repose en paix
Testé avec Excel 2002,Excel 2007,Excel 2010,Excel 2016

Code:
Private Sub Worksheet_Activate()
  Set f = Sheets("Fichier de Base")
  Set d1 = CreateObject("Scripting.Dictionary")
  TblE = f.Range("a1:b" & f.[a65000].End(xlUp).Row).Value
  For i = 1 To UBound(TblE)
    d1(TblE(i, 1)) = d1(TblE(i, 1)) & TblE(i, 2) & vbCrLf
  Next i
  [A2].Resize(d1.Count) = Application.Transpose(d1.keys)   ' 65000 clés maxi
  TblItems = d1.items: ReDim TblItems2(1 To d1.Count, 1 To 1)
  For i = 1 To d1.Count: TblItems2(i, 1) = TblItems(i - 1): Next i
  [b2].Resize(d1.Count) = TblItems2
End Sub

Boisgontier
 

Pièces jointes

  • RegroupementSautLigne.xls
    42.5 KB · Affichages: 29
Dernière édition:

Discussions similaires

Statistiques des forums

Discussions
312 161
Messages
2 085 844
Membres
103 004
dernier inscrit
ponas