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 82 83 84 85 86 87 88 89 90
| Sub tab_Realise()
'Routine de début
Dim tempcalc As Long
tempcalc = Application.Calculation
Application.EnableEvents = False
Application.ScreenUpdating = False
Application.Visible = True
Application.Calculation = xlCalculationManual
'Définition du tableau de variable
Dim tab_varA()
Dim tab_varB()
Dim tb_6()
Dim tb_7()
Dim tb_9()
Dim tb_10()
Dim tabdat_crs(1) As Long
Dim tabdat_ant(2) As Long
'Déclaration des variables
Dim dern_ligne As Long 'Cette variable représentera la dernière cellule non-vide feuil1
Dim dern_col As Long 'Cette variable représentera la dernière colonne non-vide feuil1
Dim dern_ligne_B As Long 'Cette variable représentera la dernière cellule non-vide feuil2
Dim dern_col_B As Long 'Cette variable représentera la dernière colonne non-vide feuil2
Dim i As Long 'Nous utiliserons cette variable pour les lignes dans les boucles
Dim t As Long
'définition des limites du tableau
dern_ligne = Feuil1.Cells(Rows.Count, 1).End(xlUp).Row 'Trouve la valeur de la dernière ligne non-vide de l'onglet feuil1
dern_col = Feuil1.Cells(1, Columns.Count).End(xlToLeft).Column 'Trouve la valeur de la dernière dernière colonne non-vide de l'onglet feuil1
dern_ligne_B = Feuil2.Cells(Rows.Count, 1).End(xlUp).Row 'Trouve la valeur de la dernière ligne non-vide de l'onglet feuil2
dern_col_B = Feuil2.Cells(1, Columns.Count).End(xlToLeft).Column 'Trouve la valeur de la dernière dernière colonne non-vide de l'onglet feuil2
tabdat_crs(1) = Feuil2.Range("Ex_crs") 'une donnée date inscrite dans une cellule
tabdat_ant(2) = Feuil2.Range("Ex_ant") 'une donnée date inscrite dans une cellule
'Redimensionnement du tableau A
tab_varA = Feuil1.Cells(1, 1).Resize(dern_ligne, dern_col).Value
'Redimensionnement du tableau B
tab_varB = Feuil2.Cells(1, 1).Resize(dern_ligne_B, dern_col_B).Value
' colonnes à calculer en table
tb_6 = Feuil2.Cells(1, 6).Resize(dern_ligne_B, 1).Value
tb_7 = Feuil2.Cells(1, 7).Resize(dern_ligne_B, 1).Value
tb_9 = Feuil2.Cells(1, 9).Resize(dern_ligne_B, 1).Value
tb_10 = Feuil2.Cells(1, 10).Resize(dern_ligne_B, 1).Value
For i = LBound(tab_varA, 1) To UBound(tab_varA, 1)
'Dans cette première boucle, nous allons obtenir le total général de produit
For t = LBound(tab_varB, 1) To UBound(tab_varB, 1)
'Si égalité entre tableau
If tab_varB(t, 1) = tab_varA(i, 13) And tab_varB(t, 2) = tab_varA(i, 9) And tab_varB(t, 3) = tab_varA(i, 10) And tab_varB(t, 4) = tab_varA(i, 11) And tab_varA(i, 1) = tabdat_ant(2) Then
'Résultat attendu
tb_6(t, 1) = tb_6(t, 1) + tab_varA(i, 16)
End If
If tab_varB(t, 1) = tab_varA(i, 13) And tab_varB(t, 2) = tab_varA(i, 9) And tab_varB(t, 3) = tab_varA(i, 10) And tab_varB(t, 4) = tab_varA(i, 11) And tab_varA(i, 1) = tabdat_crs(1) Then
'Résultat attendu
tb_9(t, 1) = tb_9(t, 1) + tab_varA(i, 16)
End If
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Ici nous allons boucler pour obtenir un quantité de produit plus spécifique
If tab_varA(i, 15) = "NON-Admissible" Then
'Si égalité entre tableau
If tab_varB(t, 1) = tab_varA(i, 13) And tab_varB(t, 2) = tab_varA(i, 9) And tab_varB(t, 3) = tab_varA(i, 10) And tab_varB(t, 4) = tab_varA(i, 11) And tab_varA(i, 1) = Feuil2.Range("Ex_ant") Then
'Résultat attendu
tb_7(t, 1) = tb_7(t, 1) + tab_varA(i, 16)
End If
If tab_varB(t, 1) = tab_varA(i, 13) And tab_varB(t, 2) = tab_varA(i, 9) And tab_varB(t, 3) = tab_varA(i, 10) And tab_varB(t, 4) = tab_varA(i, 11) And tab_varA(i, 1) = Feuil2.Range("Ex_crs") Then
'Résultat attendu
tb_10(t, 1) = tb_10(t, 1) + tab_varA(i, 16)
End If
End If
Next t
Next i
Feuil2.Cells(1, 6).Resize(dern_ligne_B, 1) = tb_6
Feuil2.Cells(1, 7).Resize(dern_ligne_B, 1) = tb_7
Feuil2.Cells(1, 9).Resize(dern_ligne_B, 1) = tb_9
Feuil2.Cells(1, 10).Resize(dern_ligne_B, 1) = tb_10
'routine de fin
Application.EnableEvents = True 'desactiver les evenements
Application.ScreenUpdating = True 'rafraichissement du tableau
Application.Visible = True
Application.Calculation = tempcalc
End Sub |
Partager