• Initiateur de la discussion Initiateur de la discussion garrec
  • 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 !

garrec

XLDnaute Occasionnel
Bonjour

J'ai un tableau de ce type sur Excel

en PJ

J'aimerais bien que les numéros correspondant au même nom de ligne soit sur la même ligne mais je seche 😕
Par exemple j'ai du ESM2 INDEX en ligne 1 en ligne 7 et en 16 j'aimerais que ça s'affiche sur la meme ligne?
Merci 🙂
 

Pièces jointes

Re : trier un tableau

Je viens de trouver ça:

Code:
P = Range("B" & i) <> Range("H" & j) And Range("A" & i) = Range("G" & j)
If P Then
Range("A" & i).Interior.ColorIndex = 6
End If

ça dit que

P = "Il y a une valeur différente dans les colonnes F+ de chaque tableau" ET "la valeur de code bloom est la même"
Si la condition P est remplie, alors on colorie la cellule dans la colone A du premier tableau en... Jaune pour le moment, je n'ai pas le code du orange mais quand il n'y aura plus que ça.. lol.
 
Re : trier un tableau

Bon j'en suis là:

Code:
Sub tri()
For i = 2 To 7
For j = 3 To 11
If Range("A" & i) <> Range("G" & j) Then
Range("A" & i).Interior.ColorIndex = 3
End If
If Range("A" & i) <> Range("G" & j) Then
Range("G" & j).Interior.ColorIndex = 3
End If
P = Range("B" & i) <> Range("H" & j) And Range("A" & i) = Range("G" & j)
If P Then
Range("A" & i).Interior.ColorIndex = 6
Range("G" & j).Interior.ColorIndex = 6
End If
Q = Range("C" & i) <> Range("I" & j) And Range("A" & i) = Range("G" & j)
If Q Then
Range("A" & i).Interior.ColorIndex = 6
Range("G" & j).Interior.ColorIndex = 6
End If
R = Range("D" & i) <> Range("J" & j) And Range("A" & i) = Range("G" & j)
If R Then
Range("A" & i).Interior.ColorIndex = 6
Range("G" & j).Interior.ColorIndex = 6
End If
S = Range("E" & i) <> Range("K" & j) And Range("A" & i) = Range("G" & j)
If S Then
Range("A" & i).Interior.ColorIndex = 6
Range("G" & j).Interior.ColorIndex = 6
End If
Next j
Next i


End Sub

C'est à peaufiner mais je n'ai pas le temps d'aller plus loin pour le moment. Je te souhaite bon courage, tiens moi au courant de l'avancement, je regarderais à nouveau ça ce soir si j'ai quelques minutes.

A+
 
Re : trier un tableau

Re bonjour!!

Finalement, j'ai eu une idée, j'ai testé et ça marche!!

Code:
Sub tri()
For i = 2 To 7
For j = 3 To 11
If Range("A" & i) <> Range("G" & j) Then
Range("A" & i).Interior.ColorIndex = 3
End If
If Range("A" & i) <> Range("G" & j) Then
Range("G" & j).Interior.ColorIndex = 3
End If
Next j
Next i
For k = 2 To 7
For l = 3 To 11
P = Range("A" & k) = Range("G" & l) And Range("B" & k) <> Range("H" & l)
Q = Range("A" & k) = Range("G" & l) And Range("C" & k) <> Range("I" & l)
R = Range("A" & k) = Range("G" & l) And Range("D" & k) <> Range("J" & l)
S = Range("A" & k) = Range("G" & l) And Range("E" & k) <> Range("K" & l)
If P Or Q Or R Or S Then
Range("A" & k).Interior.ColorIndex = 45
Range("G" & l).Interior.ColorIndex = 45
End If
Next l
Next k
End Sub

Y'a peut-être moyen de simplifier mais en tout cas voici ce que tu voulais. Bien sûr il reste à l'adapter à ton cas (emplacement des tableaux, colonnes et lignes ou chercher...) mais une fois que tu auras réglé ça, le code fonctionne.

Si tu as encore besoin n'hésites pas.

A+
 
Re : trier un tableau

Merci j'ai essayé sur mon classeur final!!

Regarde ce que ça donne je comprend pas trop

J'ai adapté ton code comme ceci. On ne doit pas etre loin je pense:

Sub tri()
For i = 5 To 11
For j = 5 To 21

If Range("I" & i) <> Range("Q" & j) Then
Range("I" & i).Interior.ColorIndex = 3
End If
If Range("I" & i) <> Range("Q" & j) Then
Range("Q" & j).Interior.ColorIndex = 3
End If
Next j
Next i
For k = 5 To 21
For l = 5 To 21
P = Range("I" & k) = Range("Q" & l) And Range("J" & k) <> Range("R" & l)
Q = Range("I" & k) = Range("Q" & l) And Range("K" & k) <> Range("S" & l)
R = Range("I" & k) = Range("Q" & l) And Range("L" & k) <> Range("T" & l)
S = Range("I" & k) = Range("Q" & l) And Range("M" & k) <> Range("U" & l)
If P Or Q Or R Or S Then
Range("I" & k).Interior.ColorIndex = 45
Range("Q" & l).Interior.ColorIndex = 45
End If
Next l
Next k
End Sub
 

Pièces jointes

Dernière édition:
Re : trier un tableau

Salut!

J'espère que ça ne t'as pas empêché de dormir lol 😀
J'ai intégré le code dans un bouton (plus simple quand on doit tester plein de fois pour voir si ça marche)

2 erreurs dans mon code d'hier: la première étant que si le tableau croisé dynamique ne fait pas de différence entre "Index" et "INDEX", il en est tout autrement pour VBA... D'où les quelques premières ligne du code ci-dessous qui serve à rechercher tous les "Index" et à les remplacer par "INDEX"

deuxièmement, le souci des couleurs venait du fait que vba ne peut pas recolorer une cellule qui l'est déjà.. Du moins c'est ce que j'en conclu, car le code ci-dessous marche.

Code:
Private Sub CommandButton1_Click()
'On remplace "Index" par "INDEX"
Cells.Select
    With Application.FindFormat.Font
        .Subscript = False
        .TintAndShade = 0
    End With
    Selection.Replace What:="index", Replacement:="INDEX", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
'On lance la recherche des paramètre présents dans un tableau mais pas dans l'autre
For i = 1 To 7
For j = 1 To 17
'Dans le tableau 1
If Range("A" & i) <> Range("G" & j) Then
'On efface la couleur de la cellule
Range("A" & i).Interior.ColorIndex = xlColorIndexNone
'On colorie la cellule en rouge
Range("A" & i).Interior.ColorIndex = 3
End If
'Dans le tableau 2
If Range("A" & i) <> Range("G" & j) Then
'On efface la couleur de la cellule
Range("G" & j).Interior.ColorIndex = xlColorIndexNone
'On colorie la cellule en rouge
Range("G" & j).Interior.ColorIndex = 3
End If
Next j
Next i
'Pour les codes bloom égaux, on va rechercher les différences dans les colones suivantes
For k = 1 To 7
For l = 1 To 17
P = Range("A" & k) = Range("G" & l) And Range("B" & k) <> Range("H" & l)
Q = Range("A" & k) = Range("G" & l) And Range("C" & k) <> Range("I" & l)
R = Range("A" & k) = Range("G" & l) And Range("D" & k) <> Range("J" & l)
S = Range("A" & k) = Range("G" & l) And Range("E" & k) <> Range("K" & l)
'Si les codes bloom sont les mêmes mais qu'il y à des différence dans les colones suivante, on colore les cellules en orange
If P Or Q Or R Or S Then
Range("A" & k).Interior.ColorIndex = xlColorIndexNone
Range("A" & k).Interior.ColorIndex = 45
Range("G" & l).Interior.ColorIndex = xlColorIndexNone
Range("G" & l).Interior.ColorIndex = 45
End If
'Dans chaque ligne ou on a colorer le code bloom en orange, on colorie les variations
If P Then
Range("B" & k).Interior.ColorIndex = xlColorIndexNone
Range("B" & k).Interior.ColorIndex = 45
Range("H" & l).Interior.ColorIndex = xlColorIndexNone
Range("H" & l).Interior.ColorIndex = 45
End If
If Q Then
Range("C" & k).Interior.ColorIndex = xlColorIndexNone
Range("C" & k).Interior.ColorIndex = 45
Range("I" & l).Interior.ColorIndex = xlColorIndexNone
Range("I" & l).Interior.ColorIndex = 45
End If
If R Then
Range("D" & k).Interior.ColorIndex = xlColorIndexNone
Range("D" & k).Interior.ColorIndex = 45
Range("J" & l).Interior.ColorIndex = xlColorIndexNone
Range("J" & l).Interior.ColorIndex = 45
End If
If S Then
Range("E" & k).Interior.ColorIndex = xlColorIndexNone
Range("E" & k).Interior.ColorIndex = 45
Range("K" & l).Interior.ColorIndex = xlColorIndexNone
Range("K" & l).Interior.ColorIndex = 45
End If
Next l
Next k
End Sub


Actives les macro et appuies sur "Test"
Dis moi s'il y a encore des problèmes ou si ça marche.
Le fichier ci-joint inclue ce code, et il fonctionne sur la feuille 1.

A+
 

Pièces jointes

Re : trier un tableau

J'ai trouvé le problème, en fait dans les boucles
Code:
For i = 1 To 7
For j = 1 To 17
...

Next j
Next i

Le code s'exécute en premier dans la boucle j puis dans la boucle i une fois que j=17, ensuite il compare pour les valeurs de i...

Du coup je te propose le code "bourin" ci-dessous

Code:
Private Sub CommandButton1_Click()
'On remplace "Index" par "INDEX"
Cells.Select
    With Application.FindFormat.Font
        .Subscript = False
        .TintAndShade = 0
    End With
    Selection.Replace What:="index", Replacement:="INDEX", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False
'On lance la recherche des paramètre présents dans un tableau mais pas dans l'autre
For i = 1 To 7
For j = 1 To 17
'Dans le tableau 1
If Range("A" & i) <> Range("G" & j) Then
'On efface la couleur de la cellule
Range("A" & i).Interior.ColorIndex = xlColorIndexNone
'On colorie la cellule en rouge
Range("A" & i).Interior.ColorIndex = 3
End If
'Dans le tableau 2
If Range("A" & i) <> Range("G" & j) Then
'On efface la couleur de la cellule
Range("G" & j).Interior.ColorIndex = xlColorIndexNone
'On colorie la cellule en rouge
Range("G" & j).Interior.ColorIndex = 3
End If
Next j
Next i
'Pour les codes bloom égaux, on va rechercher les différences dans les colones suivantes
For k = 1 To 7
For l = 1 To 17
P = Range("A" & k) = Range("G" & l) And Range("B" & k) <> Range("H" & l)
Q = Range("A" & k) = Range("G" & l) And Range("C" & k) <> Range("I" & l)
R = Range("A" & k) = Range("G" & l) And Range("D" & k) <> Range("J" & l)
S = Range("A" & k) = Range("G" & l) And Range("E" & k) <> Range("K" & l)
'Si les codes bloom sont les mêmes mais qu'il y à des différence dans les colones suivante, on colore les cellules en orange
If P Or Q Or R Or S Then
Range("A" & k).Interior.ColorIndex = xlColorIndexNone
Range("A" & k).Interior.ColorIndex = 45
Range("G" & l).Interior.ColorIndex = xlColorIndexNone
Range("G" & l).Interior.ColorIndex = 45
End If
'Dans chaque ligne ou on a colorer le code bloom en orange, on colorie les variations
If P Then
Range("B" & k).Interior.ColorIndex = xlColorIndexNone
Range("B" & k).Interior.ColorIndex = 45
Range("H" & l).Interior.ColorIndex = xlColorIndexNone
Range("H" & l).Interior.ColorIndex = 45
End If
If Q Then
Range("C" & k).Interior.ColorIndex = xlColorIndexNone
Range("C" & k).Interior.ColorIndex = 45
Range("I" & l).Interior.ColorIndex = xlColorIndexNone
Range("I" & l).Interior.ColorIndex = 45
End If
If R Then
Range("D" & k).Interior.ColorIndex = xlColorIndexNone
Range("D" & k).Interior.ColorIndex = 45
Range("J" & l).Interior.ColorIndex = xlColorIndexNone
Range("J" & l).Interior.ColorIndex = 45
End If
If S Then
Range("E" & k).Interior.ColorIndex = xlColorIndexNone
Range("E" & k).Interior.ColorIndex = 45
Range("K" & l).Interior.ColorIndex = xlColorIndexNone
Range("K" & l).Interior.ColorIndex = 45
End If
Next l
Next k
For n = 1 To 7
For m = 1 To 17
T = Range("A" & n) = Range("G" & m) And Range("B" & n) = Range("H" & m) And Range("C" & n) = Range("I" & m) And Range("D" & n) = Range("J" & m) And Range("E" & n) = Range("K" & m)
'Dans le tableau 1
If T Then
'On efface la couleur de la plage de cellule
Range("A" & n, "E" & n).Interior.ColorIndex = xlColorIndexNone
End If
'Dans le tableau 2
If T Then
'On efface la couleur de la plage de cellule
Range("G" & m, "K" & m).Interior.ColorIndex = xlColorIndexNone
End If
Next m
Next n
Range("A1").Select
End Sub

C'est du lourd, je pense que ça va faire pleurer des gens de ce forum lol, mais au moins ça marche.

Test et dis moi.

A+
 
Re : trier un tableau

oui c'est exactement ça tiens voila le code modifié qui marche quand on ecrit index en majuscule partout

Code:
Sub CommandButton1_Click()
 'On remplace "Index" par "INDEX"
 Cells.Select
     With Application.FindFormat.Font
         .Subscript = False
         .TintAndShade = 0
     End With
     Selection.Replace What:="index", Replacement:="INDEX", LookAt:=xlPart, _
         SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
         ReplaceFormat:=False
 'On lance la recherche des paramètre présents dans un tableau mais pas dans l'autre
 For i = 5 To 21
 For j = 5 To 21
 'Dans le tableau 1
 If Range("H" & i) <> Range("O" & j) Then
 'On efface la couleur de la cellule
 Range("H" & i).Interior.ColorIndex = xlColorIndexNone
 'On colorie la cellule en rouge
 Range("H" & i).Interior.ColorIndex = 3
 End If
 'Dans le tableau 2
 If Range("H" & i) <> Range("O" & j) Then
 'On efface la couleur de la cellule
 Range("O" & j).Interior.ColorIndex = xlColorIndexNone
 'On colorie la cellule en rouge
 Range("O" & j).Interior.ColorIndex = 3
 End If
 Next j
 Next i
 'Pour les codes bloom égaux, on va rechercher les différences dans les colones suivantes
 For k = 5 To 21
 For l = 5 To 21
 P = Range("H" & k) = Range("O" & l) And Range("I" & k) <> Range("P" & l)
 Q = Range("H" & k) = Range("O" & l) And Range("J" & k) <> Range("Q" & l)
 R = Range("H" & k) = Range("O" & l) And Range("K" & k) <> Range("R" & l)
 S = Range("H" & k) = Range("O" & l) And Range("L" & k) <> Range("S" & l)
 'Si les codes bloom sont les mêmes mais qu'il y à des différence dans les colones suivante, on colore les cellules en orange
 If P Or Q Or R Or S Then
 Range("H" & k).Interior.ColorIndex = xlColorIndexNone
 Range("H" & k).Interior.ColorIndex = 45
 Range("O" & l).Interior.ColorIndex = xlColorIndexNone
 Range("O" & l).Interior.ColorIndex = 45
 End If
 'Dans chaque ligne ou on a colorer le code bloom en orange, on colorie les variations
 If P Then
 Range("I" & k).Interior.ColorIndex = xlColorIndexNone
 Range("I" & k).Interior.ColorIndex = 45
 Range("P" & l).Interior.ColorIndex = xlColorIndexNone
 Range("P" & l).Interior.ColorIndex = 45
 End If
 If Q Then
 Range("J" & k).Interior.ColorIndex = xlColorIndexNone
 Range("J" & k).Interior.ColorIndex = 45
 Range("Q" & l).Interior.ColorIndex = xlColorIndexNone
 Range("Q" & l).Interior.ColorIndex = 45
 End If
 If R Then
 Range("K" & k).Interior.ColorIndex = xlColorIndexNone
 Range("K" & k).Interior.ColorIndex = 45
 Range("R" & l).Interior.ColorIndex = xlColorIndexNone
 Range("R" & l).Interior.ColorIndex = 45
 End If
 If S Then
 Range("L" & k).Interior.ColorIndex = xlColorIndexNone
 Range("L" & k).Interior.ColorIndex = 45
 Range("S" & l).Interior.ColorIndex = xlColorIndexNone
 Range("S" & l).Interior.ColorIndex = 45
 End If
 Next l
 Next k
 For n = 5 To 21
 For m = 5 To 21
 T = Range("H" & n) = Range("O" & m) And Range("I" & n) = Range("P" & m) And Range("J" & n) = Range("Q" & m) And Range("K" & n) = Range("R" & m) And Range("L" & n) = Range("S" & m)
 'Dans le tableau 1
 If T Then
 'On efface la couleur de la plage de cellule
 Range("H" & n, "L" & n).Interior.ColorIndex = xlColorIndexNone
 End If
 'Dans le tableau 2
 If T Then
 'On efface la couleur de la plage de cellule
 Range("O" & m, "S" & m).Interior.ColorIndex = xlColorIndexNone
 End If
 Next m
 Next n
 Range("A1").Select
 End Sub
 
Re : trier un tableau

Hey bonjour Venitien

Le code fonctionne bien sur lefichier précedent. J'ai rajouté 1 ou 2 petites choses à la fin. Le voici

Code:
Sub CommandButtonOption_Click()

 'On lance la recherche des paramètre présents dans un tableau mais pas dans l'autre
 For i = 4 To 50
 For j = 4 To 50
 'Dans le tableau 1
 If Range("H" & i) <> Range("O" & j) Then
 'On efface la couleur de la cellule
 Range("H" & i).Interior.ColorIndex = xlColorIndexNone
 'On colorie la cellule en rouge
 Range("H" & i).Interior.ColorIndex = 3
 End If
 'Dans le tableau 2
 If Range("H" & i) <> Range("O" & j) Then
 'On efface la couleur de la cellule
 Range("O" & j).Interior.ColorIndex = xlColorIndexNone
 'On colorie la cellule en rouge
 Range("O" & j).Interior.ColorIndex = 3
 End If
 Next j
 Next i
 'Pour les codes bloom égaux, on va rechercher les différences dans les colones suivantes
 For k = 4 To 50
 For l = 4 To 50
 p = Range("H" & k) = Range("O" & l) And Range("I" & k) <> Range("P" & l)
 Q = Range("H" & k) = Range("O" & l) And Range("J" & k) <> Range("Q" & l)
 R = Range("H" & k) = Range("O" & l) And Range("K" & k) <> Range("R" & l)
 S = Range("H" & k) = Range("O" & l) And Range("L" & k) <> Range("S" & l)
 'Si les codes bloom sont les mêmes mais qu'il y à des différence dans les colones suivante, on colore les cellules en orange
 If p Or Q Or R Or S Then
 Range("H" & k).Interior.ColorIndex = xlColorIndexNone
 Range("H" & k).Interior.ColorIndex = 45
 Range("O" & l).Interior.ColorIndex = xlColorIndexNone
 Range("O" & l).Interior.ColorIndex = 45
 End If
 'Dans chaque ligne ou on a colorer le code bloom en orange, on colorie les variations
 If p Then
 Range("I" & k).Interior.ColorIndex = xlColorIndexNone
 Range("I" & k).Interior.ColorIndex = 45
 Range("P" & l).Interior.ColorIndex = xlColorIndexNone
 Range("P" & l).Interior.ColorIndex = 45
 End If
 If Q Then
 Range("J" & k).Interior.ColorIndex = xlColorIndexNone
 Range("J" & k).Interior.ColorIndex = 45
 Range("Q" & l).Interior.ColorIndex = xlColorIndexNone
 Range("Q" & l).Interior.ColorIndex = 45
 End If
 If R Then
 Range("K" & k).Interior.ColorIndex = xlColorIndexNone
 Range("K" & k).Interior.ColorIndex = 45
 Range("R" & l).Interior.ColorIndex = xlColorIndexNone
 Range("R" & l).Interior.ColorIndex = 45
 End If
 If S Then
 Range("L" & k).Interior.ColorIndex = xlColorIndexNone
 Range("L" & k).Interior.ColorIndex = 45
 Range("S" & l).Interior.ColorIndex = xlColorIndexNone
 Range("S" & l).Interior.ColorIndex = 45
 End If
 Next l
 Next k
 For n = 4 To 50
 For m = 4 To 50
 T = Range("H" & n) = Range("O" & m) And Range("I" & n) = Range("P" & m) And Range("J" & n) = Range("Q" & m) And Range("K" & n) = Range("R" & m) And Range("L" & n) = Range("S" & m)
 'Dans le tableau 1
 If T Then
 'On efface la couleur de la plage de cellule
 Range("H" & n, "L" & n).Interior.ColorIndex = xlColorIndexNone
 End If
 'Dans le tableau 2
 If T Then
 'On efface la couleur de la plage de cellule
 Range("O" & m, "S" & m).Interior.ColorIndex = xlColorIndexNone
 End If
 Next m
 Next n
 Range("A1").Select
 
 For i = 4 To 50
 
 If Range("P" & i).Value = 0 And Range("Q" & i).Value = 0 And Range("R" & i).Value = 0 And Range("S" & i).Value = 0 Then
 
 Range("O" & i).Interior.ColorIndex = xlColorIndexNone
 
 
 
 End If
 
 Next
  
 For m = 4 To 50

If Range("H" & m).Value = "Total général" Then

Range("H" & m).Interior.ColorIndex = xlColorIndexNone
 
End If

Next

 
 For m = 4 To 50

If Range("H" & m).Value = "" Then

Range("H" & m).Interior.ColorIndex = xlColorIndexNone
 
End If

Next





 End Sub


Mais je ne comprend pas pk il ne fonctionne pas sur ce fichier là??

hAVE A GOOD DAY

Thanks in advance 😉
 

Pièces jointes

- 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

  • Question Question
Microsoft 365 Fonction si
Réponses
7
Affichages
221
  • Question Question
Microsoft 365 Tableau
Réponses
5
Affichages
288
Réponses
18
Affichages
724
Réponses
14
Affichages
488
  • Question Question
Microsoft 365 problème d'index
Réponses
19
Affichages
498
Retour