Bonjour,

Un utilisateur m'a soumis ce cas. Une macro met 8 - 10 sec pour s'exécuter et 1,5 sec si on clique en dehors de la fenêtre Excel. Le code est le suivant (tel quel, mais le problème est le même après optimisation) :

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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
Sub Aplatisseur()
 
  Dim f As String
  Dim pos, Diviseur As Double
 
  f = "SAISIE DONNÉES"
  pos = 2  'la ligne où on écrit dans DATA
 
  Sheets("DATA").Activate
  Rows("2:1000000").Delete
  ActiveSheet.UsedRange
 
  Application.ScreenUpdating = False
  Application.Calculation = xlCalculationManual
  Application.EnableEvents = False
 
  For i = 5 To Sheets(f).Range("C1000000").End(xlUp).Row
 
    Application.StatusBar = "Compilation..." & Round((i / Sheets(f).Range("C1000000").End(xlUp).Row) * 100, 0) & "%"
 
    For j = 26 To 175 'colonnes numériques
 
     'Pour les lignes avec classifications et sans erreur, quand il y a un montant (volume, tarif, $$)
      If Sheets(f).Columns(j).EntireColumn.Hidden = False And _
         Sheets(f).Cells(i, j) <> 0 And Sheets(f).Cells(i, j) <> "" And _
         Sheets(f).Range("FV" & i) <> "" And Sheets(f).Range("FT" & i) = "" Then
 
        Range("V" & pos) = IIf(Sheets(f).Range("Y" & i) = "Flux monétaire", "FLUX MONÉTAIRE", "IMPACT RÉSULTATS") 'Vue
 
        Range("W" & pos) = Sheets(f).Cells(4, j) 'Année du montant
 
        If j >= 26 And j <= 50 Then
          Range("X" & pos) = Sheets(f).Cells(i, j) 'volumes
        End If
 
        If j >= 51 And j <= 75 Then Range("Y" & pos) = Sheets(f).Cells(i, j) 'tarif
 
        If j >= 76 And j <= 100 Then                 'mois projet
          Range("Z" & pos) = "PROJET"
          Range("AA" & pos) = Sheets(f).Cells(i, j)
        End If
 
        If j >= 101 And j <= 125 Then                '$$ projet
          Range("Z" & pos) = "PROJET"
          Range("AB" & pos) = Sheets(f).Cells(i, j)
        End If
 
        If j >= 126 And j <= 150 Then                'mois oper
          Range("Z" & pos) = "OPÉRATIONNEL"
          Range("AA" & pos) = Sheets(f).Cells(i, j)
        End If
 
        If j >= 151 And j <= 175 Then                '$$ oper
          Range("Z" & pos) = "OPÉRATIONNEL"
          Range("AB" & pos) = Sheets(f).Cells(i, j)
        End If
 
       'Récupérer le reste de la ligne
        For k = 4 To 24
          Cells(pos, k - 3) = Sheets(f).Cells(i, k).Value
        Next
 
        Range("C" & pos) = Sheets(f).Range("FV" & i)
 
        pos = pos + 1
 
      End If
 
    Next
 
  Next
 
  Application.Calculation = xlCalculationAutomatic
  Application.ScreenUpdating = True
  Application.EnableEvents = True
 
  Application.StatusBar = ""
 
End Sub
Avez-vous jamais rencontré un tel cas ?

Cordialement.

Daniel