Bonjour à tous,

Je viens de réaliser mon premier programme en variable tableau pour un traitement normalement plus rapide. J'ai donc respecté les règles du ScreenUpdating sur False, le calcul manuel, de limiter les Range et cells (chargement du tableau complet en 1 seul) et pourtant il continu de ramer !!!.
Le but du programme est d'additionner plusieurs colonnes (5 dans ce cas) d'un tableau qui en comporte 125 et de faire la somme. Pour tenter d'aller plus vite j'additionne colonne par colonne mais je pense que le problème vient de la boucle For A parce que le calcul est réalisé par ligne, enfin pure hypothèse, cependant plus le nombre de lignes est important plus le temps de traitement s'allonge.
Si quelqu'un pouvait me renseigner sur mes erreurs !!!

Cordialement

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
80
81
Sub tableauV2()
Dim T As Variant, A%
Dim a1%, a2%, a3%, a4%, a5%
Dim b1%, b2%, b3%, b4%, b5%
Dim c1%, c2%, c3%, c4%, c5%
Dim x%, y%
Dim tStart As Double, tEnd As Double
 
tStart = Time
Application.ScreenUpdating = False
Application.Calculation = xlManual
 
With Worksheets("A") 'feuille active
'Remplir le tableau des données de la plage
T = .Range("A5:DX" & Cells(Rows.Count, 1).End(xlUp).Row).Value
End With
 
'boucle sur colonne
For a1 = 1 To 121
    For a2 = a1 + 1 To 122
        For a3 = a2 + 1 To 123
            For a4 = a3 + 1 To 124
                For a5 = a4 + 1 To 125
'Boucle sur le tableau
                    For A = LBound(T, 1) To UBound(T, 1)
 
                    T(A, 127) = T(A, a1) + T(A, a2) + T(A, a3) + T(A, a4) + T(A, a5) 'addition des colonnes
                    If T(A, 127) > 0 Then T(A, 128) = 1 Else: T(A, 128) = 0 'test si element colonne 127>0 alors 1 sinon 0 en colonne 128
 
                    Next A
        'x = x + 1 'compte le nombre de boucles
        x = Application.Sum(Application.Index(T, , 128)) 'compte le nombre de données en colonne 128
 
        If x = y Then
        c1 = a1
        c2 = a2
        c3 = a3
        c4 = a4
        c5 = a5
        End If
 
        If x > y Then 'test pour garder la combinaison la plus élevée
        y = x
        b1 = a1
        b2 = a2
        b3 = a3
        b4 = a4
        b5 = a5
        End If
 
 
'MsgBox x
                Next
            Next
        Next
    Next
Next
 
'copie du tableau
With Worksheets("A")
'.Range("A4").Resize(UBound(T, 1), UBound(T, 2)) = T
.Range("EA1") = y
.Range("EB1") = b1
.Range("EC1") = b2
.Range("ED1") = b3
.Range("EE1") = b4
.Range("EF1") = b5
.Range("EB2") = c1
.Range("EC2") = c2
.Range("ED2") = c3
.Range("EE2") = c4
.Range("EF2") = c5
'.Range("EG1") = x
End With
 
tEnd = Time
Range("EJ1") = Format(tEnd - tStart, "HH:MM:SS")
Application.ScreenUpdating = True
Application.Calculation = xlAutomatic
ActiveWorkbook.Save
End Sub