• Initiateur de la discussion Initiateur de la discussion bobjazz
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

bobjazz

XLDnaute Impliqué
Bonjour le Forum

Je redemande mon aide sur un fichier, je pense que je n'etais pas assez precis.
Mon but, je récupère des fichiers pour en faire un seul. Après je trie tout cela pour pouvoir l'exploiter.
Dans mon fichier joint, je montre l'avant et aprés, sachant que j'arrive à trier environ 100 lignes sur 8 à 10 colonnes

Merci d'avance

bobjazz
 

Pièces jointes

Re : Tri et classement

Bonsoir,

un solution à base de TCD (merci l'enregistreur de macro!)
Code:
Sub Bobjazz()
Selection.CurrentRegion.Select
Set wzone = Selection
nbligne = wzone.Rows.Count - 1
derligne = wzone.Row + nbligne
nbcol = wzone.Columns.Count
dercol = wzone.Column + nbcol - 1
For j = dercol To wzone.Column Step -2
    Cells(1, j + 1).EntireColumn.Insert Shift:=xlToRight
    Cells(wzone.Row, j).Select
    Selection.Copy
    Range(Cells(wzone.Row + 1, j + 1), Cells(wzone.Row + nbligne, j + 1)).Select
    ActiveSheet.Paste
Next j
For i = 0 To Int(nbcol / 2) - 1
    vdest = Cells(65536, wzone.Column).End(xlUp).Row + 1
    Range(Cells(wzone.Row + 1, wzone.Column + (i + 1) * 3), _
        Cells(wzone.Row + nbligne, wzone.Column + (i + 1) * 3 + 2)).Select
    Application.CutCopyMode = False
    Selection.Cut Destination:=Cells(vdest, wzone.Column)
Next i
Cells(wzone.Row, wzone.Column).Select
Selection.CurrentRegion.Select
Selection.Sort Key1:=Cells(wzone.Row, wzone.Column), Order1:=xlAscending, Header:=xlYes, _
    OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortNormal
Range(Cells(wzone.Row, wzone.Column + 3), Cells(wzone.Row, wzone.Column + (Int(nbcol / 2)) * 3 - 1)).EntireColumn.Select
Selection.Delete Shift:=xlLeft
Cells(wzone.Row, wzone.Column + 1).Select
ActiveCell.FormulaR1C1 = "montant"
Cells(wzone.Row, wzone.Column + 2).Select
ActiveCell.FormulaR1C1 = "type"
Selection.CurrentRegion.Select
Set wz_tcd = Selection
wsd = "'" & ActiveSheet.Name & "'!" & wz_tcd.Address(ReferenceStyle:=xlR1C1)
wdest = "'[" & ActiveWorkbook.Name & "]" & ActiveSheet.Name & "'!" & wz_tcd(1, 1).Offset(0, 4).Address(ReferenceStyle:=xlR1C1)
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:=wsd).CreatePivotTable TableDestination:= _
    wdest, TableName:="Tableau croisé dynamique1", DefaultVersion:=xlPivotTableVersion10
With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("Noms")
    .Orientation = xlRowField
    .Position = 1
End With
ActiveSheet.PivotTables("Tableau croisé dynamique1").AddDataField ActiveSheet. _
    PivotTables("Tableau croisé dynamique1").PivotFields("montant"), _
    "Somme de montant", xlSum
With ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotFields("type")
    .Orientation = xlColumnField
    .Position = 1
End With
ActiveSheet.PivotTables("Tableau croisé dynamique1").PivotSelect "", _
    xlDataAndLabel, True
Selection.Copy
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
    :=False, Transpose:=False
Application.CutCopyMode = False
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
    .LineStyle = xlContinuous
    .Weight = xlThin
    .ColorIndex = xlAutomatic
End With
Range(wz_tcd(2, 1).Offset(0, 5), wz_tcd(2, 1).Offset(0, 5 + Int(nbcol / 2))).Select
With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
End With
Selection.Font.Bold = True
With Selection.Interior
    .ColorIndex = 40
    .Pattern = xlSolid
End With
Range(wz_tcd(1, 1).Offset(0, 5), wz_tcd(1, 1).Offset(0, 5 + Int(nbcol / 2) - 1)).Select
With Selection
    .HorizontalAlignment = xlCenter
    .VerticalAlignment = xlBottom
    .WrapText = False
    .Orientation = 0
    .AddIndent = False
    .IndentLevel = 0
    .ShrinkToFit = False
    .ReadingOrder = xlContext
    .MergeCells = False
End With
Selection.Merge
Selection.Font.Bold = True
wz_tcd(1, 1).Offset(0, 4).ClearContents
End Sub
il faut positionner le curseur dans une cellule du tableau initial avant de lancer la macro

A+
 
Re : Tri et classement

Re Bonsoir Hervé

Ta macro me bug, elle trie bien mais affiche toujours la même suite de chiffre, je te joint la vrai configuration, peut etre vient de là.
Dans ton code tu parles de i, j, k et l As Integer, j'ai Plus de colonnes, est ce qu'i faut en rajouter, j'ai essaye bug

Merci d'avance

bobjazz
 

Pièces jointes

Re : Tri et classement

Salut bobjazz
bonsoir le fil

arrf il me faut saluer mon Ami Hervé ,donc j'interviens lol

il faut que tu mettes les entêtes de colonnes pour avoir le bon résultat
pour ce qui est des colonnes Hervé à fait une détection de la derniere colonne du tableau

Code:
 nbcolonnes = Range("iv6").End(xlToLeft).Column

bon ca c'est fait lol 😀

J'espère que tu vas bien Hervé ,car tu te fais rare lol
sinon beau travail comme dab Lol 😀
bonne fin de soirée
 
Dernière édition:
Re : Tri et classement

re bob, salut odjv, chti

oui bob, j'ai fait le code suivant ton tableau, apres il faut l'adapter à ton fichier réel.

le nombre de colonne est donnée comme dit chti, sur cette ligne :

nbcolonnes = Range("iv5").End(xlToLeft).Column

si tu met tes entetes de colonnes en ligne 6, à toi d'adapter le code.

merci chti, pour tes salues, j'espère que tout va bien pour toi.

si tu passes par lyon un de ces jours, fait moi signe, on se fera une bouffe 🙂

salut
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Retour