Bonjour,

J'ai ce code qui semble un peu long, et pousse Excel à afficher "Ne répond pas" pendant l'exécution de la macro. Est-ce que quelqu'un a une idée sur la façon dont on peut l'optimiser?

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
nombre_element_ligne_3 = .Cells(3, Columns.Count).End(xlToLeft).Column
 
                            somme = 0
                            For I = 4 To nombre_element_ligne_3
                            somme = somme + .Cells(3, I).Value
                            Next I
 
                            For I = 4 To nombre_element_ligne_3
 
 
                                    For j = 4 To 99
                                    .Cells(j, I) = .Cells(j, 1) * .Cells(3, I) / somme
                                    If .Cells(j, I) > .Cells(3, I) Then
                                    .Cells(j, I).Interior.Color = RGB(255, 0, 0)
                                    End If
 
                                    Next j
 
                                    For j = 104 To 199
                                    .Cells(j, I) = .Cells(j, 1) * .Cells(3, I) / somme
                                    If .Cells(j, I) > .Cells(3, I) Then
                                    .Cells(j, I).Interior.Color = RGB(255, 0, 0)
                                    End If
                                    Next j
 
                                    For j = 204 To 299
                                    .Cells(j, I) = .Cells(j, 1) * .Cells(3, I) / somme
                                    If .Cells(j, I) > .Cells(3, I) Then
                                    .Cells(j, I).Interior.Color = RGB(255, 0, 0)
                                    End If
                                    Next j
 
                                    For j = 304 To 399
                                    .Cells(j, I) = .Cells(j, 1) * .Cells(3, I) / somme
                                    If .Cells(j, I) > .Cells(3, I) Then
                                    .Cells(j, I).Interior.Color = RGB(255, 0, 0)
                                    End If
                                    Next j
 
                            Next I
Cordialement