Bonjour,

Je souhaite griser les lignes qui contiennent le meme numéro de facture (soit la meme valeur dans la colonne Z).

J'ai globalement réussie a faire ce que je souhaitais seulement pour plus de 34 000 enregistrement mon code fait planter Excel.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
 
Sub test()
 
    Dim state As Boolean
    Dim lastColo As Integer
    Dim nbLigne As Long
    Dim nbColonne As Long
 
    'nbLigne = Range("B65536").End(xlUp).Row
    'nbColonne = Cells(1, Columns.Count).End(xlToLeft).Column
 
    'nbLigne = 1000
    'nbColonne = 96
 
    'MsgBox nbColonne
 
    state = False
    lastColor = 15
 
    For i = 1 To nbLigne
 
        If Range("Z1").Offset(i, 0).Value = Range("Z1").Offset(i + 1, 0).Value Then
 
            For n = 0 To nbColonne
 
                If state = False And lastColor = 15 Then
                    Range("A1").Offset(i, n).Interior.Color = RGB(200, 200, 200)
                    Range("A1").Offset(i + 1, n).Interior.Color = RGB(200, 200, 200)
                    lastColor = 0
                    state = True
                ElseIf state = False And lastColor = 0 Then
                    lastColor = 15
                    Range("A1").Offset(i, n).Interior.Color = RGB(200 + lastColor, 200 + lastColor, 200 + lastColor)
                    Range("A1").Offset(i + 1, n).Interior.Color = RGB(200 + lastColor, 200 + lastColor, 200 + lastColor)
                    lastColor = 15
                    state = True
                Else
                    Range("A1").Offset(i, n).Interior.Color = RGB(200 + lastColor, 200 + lastColor, 200 + lastColor)
                    Range("A1").Offset(i + 1, n).Interior.Color = RGB(200 + lastColor, 200 + lastColor, 200 + lastColor)
                End If
 
            Next n
 
            state = True
        Else
            state = False
 
        End If
 
    Next i
 
End Sub
Avez vous une idée pour optimiser mon code ?

Merci beaucoup de votre aide