IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Macros et VBA Excel Discussion :

Optimisation de calcul


Sujet :

Macros et VBA Excel

  1. #1
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Juin 2013
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Juin 2013
    Messages : 114
    Par défaut Optimisation de calcul
    Bonjour,

    Je vous expose un peu mon problème...
    Chaque ligne a des calculs qui sont relativement long.

    Problème c'est que des que je rajoute une ligne au lieu de me calculer que la ligne, il me recalcule tous... Alors si une ligne = 10 seconde, imaginez si j'ai 10 lignes lol...
    Est ce possible de dire, des que ma cellule B2 change je calcule que la ligne 2.
    Si B3 change je calcul que ma ligne 3.

    C'est une question d'optimisation...

    Une solution les amis?

  2. #2
    Rédacteur
    Avatar de Philippe Tulliez
    Homme Profil pro
    Formateur, développeur et consultant Excel, Access, Word et VBA
    Inscrit en
    Janvier 2010
    Messages
    13 182
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Formateur, développeur et consultant Excel, Access, Word et VBA

    Informations forums :
    Inscription : Janvier 2010
    Messages : 13 182
    Billets dans le blog
    53
    Par défaut
    Bonjour,
    Si le recalcule est effectué pour l'ensemble de la feuille c'est que soit l'insertion de la ligne entre dans la plage de calcul (par exemple la somme ou la moyenne) soit qu'une ou plusieurs cellules de n'importe quelle feuille, de n'importe quel classeur ouvert contient une ou plusieurs formules volatiles.
    Les 8 formules volatiles d'excel sont AUJOURDHUI, MAINTENANT, INDIRECT, DECALER, ALEA, ALEA.ENTRE.BORNES, INFO et CELLULE.
    Et lorsque l'on parle de volatilité, c'est l'ensemble des formules imbriquées avec des formules volatiles qui se recalculent.
    Une autre possibilité est de sésactiver le calcul automatique dans les options de calcul et de faire F9 pour provoquer le calcul.
    Philippe Tulliez
    Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément. (Nicolas Boileau)
    Lorsque vous avez la réponse à votre question, n'oubliez pas de cliquer sur et si celle-ci est pertinente pensez à voter
    Mes tutoriels : Utilisation de l'assistant « Insertion de fonction », Les filtres avancés ou élaborés dans Excel
    Mon dernier billet : Utilisation de la fonction Dir en VBA pour vérifier l'existence d'un fichier

  3. #3
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Juin 2013
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Juin 2013
    Messages : 114
    Par défaut
    Justement les calcul sur toute la ligne se font par rapport à la case B de la même ligne. Donc pas de moyenne etc... Mais à chaque fois il me recalcule tout... Il y a pas moyen de faire : si la case B change de valeur alors calculer la ligne? Bizarre, c'est embêtant tout ca...

  4. #4
    Rédacteur
    Avatar de Philippe Tulliez
    Homme Profil pro
    Formateur, développeur et consultant Excel, Access, Word et VBA
    Inscrit en
    Janvier 2010
    Messages
    13 182
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Formateur, développeur et consultant Excel, Access, Word et VBA

    Informations forums :
    Inscription : Janvier 2010
    Messages : 13 182
    Billets dans le blog
    53
    Par défaut
    Bonjour,
    Citation Envoyé par guismoman60 Voir le message
    Justement les calcul sur toute la ligne se font par rapport à la case B de la même ligne. Donc pas de moyenne etc... Mais à chaque fois il me recalcule tout... Il y a pas moyen de faire : si la case B change de valeur alors calculer la ligne? Bizarre, c'est embêtant tout ca...
    Non.
    A moins de décocher l'option et la réactiver ensuite après avoir inséré toutes les lignes (manuellement ou par code VBA) je ne vois pas de solution.
    Tu dois avoir un classeur bien chargé pour avoir ce temps de recalcul aussi long.
    Philippe Tulliez
    Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément. (Nicolas Boileau)
    Lorsque vous avez la réponse à votre question, n'oubliez pas de cliquer sur et si celle-ci est pertinente pensez à voter
    Mes tutoriels : Utilisation de l'assistant « Insertion de fonction », Les filtres avancés ou élaborés dans Excel
    Mon dernier billet : Utilisation de la fonction Dir en VBA pour vérifier l'existence d'un fichier

  5. #5
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Juin 2013
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Juin 2013
    Messages : 114
    Par défaut
    Exact... J'ai revu donc tous mon programme...

    et j'ai deux problèmes :

    1- Ma variable j correspond au numéro de la ligne active. Ce que je veux réellement c'est prendre le numéro de ligne de ma variable code produit. Je ne connais pas le moyen de récupérer le numéro de ligne d'un paramètre.

    2- A la fin de mon programme je veux afficher des valeurs dans des cellules bien précise, et la encore réponse : #VALEUR.

    Attention avant de lancer ce message, cela fait 2h que je test avec le débug, et impossible de trouver pourquoi...

    Merci pour vos futurs conseils, c'est très agréable de pouvoir s'entraider comme ça...

    Voici mon code :
    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
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    Function diffstockj8(code_produit As String)
    Dim i As Integer
    Dim total_stock As Integer
    Dim stock As Integer
    Dim diffstockj1 As Integer
    Dim diffstockj2 As Integer
    Dim diffstockj3 As Integer
    Dim diffstockj4 As Integer
    Dim diffstockj5 As Integer
    Dim diffstockj6 As Integer
    Dim diffstockj7 As Integer
    Dim code_produit_cherche As String
    Dim total_cherche_sortiej1 As Integer
    Dim total_cherche_entrej1 As Integer
    Dim cherche_sortiej1 As Integer
    Dim cherche_entrej1 As Integer
    Dim cherche_sortiej2 As Integer
    Dim cherche_entrej2 As Integer
    Dim total_cherche_sortiej2 As Integer
    Dim total_cherche_entrej2 As Integer
    Dim cherche_sortiej3 As Integer
    Dim cherche_entrej3 As Integer
    Dim total_cherche_sortiej3 As Integer
    Dim total_cherche_entrej3 As Integer
    Dim cherche_sortiej4 As Integer
    Dim cherche_entrej4 As Integer
    Dim total_cherche_sortiej4 As Integer
    Dim total_cherche_entrej4 As Integer
    Dim cherche_sortiej5 As Integer
    Dim cherche_entrej5 As Integer
    Dim total_cherche_sortiej5 As Integer
    Dim total_cherche_entrej5 As Integer
    Dim cherche_sortiej6 As Integer
    Dim cherche_entrej6 As Integer
    Dim total_cherche_sortiej6 As Integer
    Dim total_cherche_entrej6 As Integer
    Dim cherche_sortiej7 As Integer
    Dim cherche_entrej7 As Integer
    Dim total_cherche_sortiej7 As Integer
    Dim total_cherche_entrej7 As Integer
    Dim cherche_sortiej8 As Integer
    Dim cherche_entrej8 As Integer
    Dim total_cherche_sortiej8 As Integer
    Dim total_cherche_entrej8 As Integer
    Dim rech As String
     
    j = ActiveCell.Row
     
     
    Application.Calculation = xlManual
    'je fais la diffstock si c'est un article
    If Left(code_produit, 4) <> "CAMP" Then
    'je cherche la sortie
        For i = 4 To 10000
            code_produit_cherche = Sheets("PDP Usine 02").Cells(i, 2)
            If Sheets("PDP Usine 02").Cells(i, 2) = "" And Sheets("PDP Usine 02").Cells(i + 1, 2) = "" And Sheets("PDP Usine 02").Cells(i + 2, 2) = "" And Sheets("PDP Usine 02").Cells(i + 3, 2) = "" And Sheets("PDP Usine 02").Cells(i + 4, 2) = "" Then
                Exit For
            Else:
     
                If code_produit_cherche = code_produit Then
                    stock = Sheets("PDP Usine 02").Cells(i, 8)
     
                    If Sheets("PDP Usine 02").Cells(i + 1, 8) = "S" Then
                        cherche_sortiej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
                        cherche_sortiej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
                        cherche_sortiej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
                        cherche_sortiej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
                        cherche_sortiej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
                        cherche_sortiej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
                        cherche_sortiej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
                        cherche_sortiej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
                      ElseIf Sheets("PDP Usine 02").Cells(i + 1, 8) = "E" Then
                        cherche_entrej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
                        cherche_entrej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
                        cherche_entrej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
                        cherche_entrej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
                        cherche_entrej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
                        cherche_entrej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
                        cherche_entrej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
                        cherche_entrej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
                    End If
     
                    If Sheets("PDP Usine 02").Cells(i + 2, 8) = "S" Then
                        cherche_sortiej1 = Sheets("PDP Usine 02").Cells(i + 2, 11)
                        cherche_sortiej2 = Sheets("PDP Usine 02").Cells(i + 2, 12)
                        cherche_sortiej3 = Sheets("PDP Usine 02").Cells(i + 2, 13)
                        cherche_sortiej4 = Sheets("PDP Usine 02").Cells(i + 2, 14)
                        cherche_sortiej5 = Sheets("PDP Usine 02").Cells(i + 2, 15)
                        cherche_sortiej6 = Sheets("PDP Usine 02").Cells(i + 2, 16)
                        cherche_sortiej7 = Sheets("PDP Usine 02").Cells(i + 2, 17)
                        cherche_sortiej8 = Sheets("PDP Usine 02").Cells(i + 2, 18)
     
     
     
                    ElseIf Sheets("PDP Usine 02").Cells(i + 2, 8) = "E" Then
                        cherche_entrej1 = Sheets("PDP Usine 02").Cells(i + 2, 11)
                        cherche_entrej2 = Sheets("PDP Usine 02").Cells(i + 2, 12)
                        cherche_entrej3 = Sheets("PDP Usine 02").Cells(i + 2, 13)
                        cherche_entrej4 = Sheets("PDP Usine 02").Cells(i + 2, 14)
                        cherche_entrej5 = Sheets("PDP Usine 02").Cells(i + 2, 15)
                        cherche_entrej6 = Sheets("PDP Usine 02").Cells(i + 2, 16)
                        cherche_entrej7 = Sheets("PDP Usine 02").Cells(i + 2, 17)
                        cherche_entrej8 = Sheets("PDP Usine 02").Cells(i + 2, 18)
                     End If
     
                   Exit For
                End If
            End If
     
        Next
     
    Sheets("PLANNING").Cells(j, 20).Value = stock
    diffstockj1 = Int(cherche_entrej1) + Int(cherche_sortiej1) + Int(stock)
    diffstockj2 = Int(cherche_entrej2) + Int(cherche_sortiej2) + diffstockj1
    diffstockj3 = Int(cherche_entrej3) + Int(cherche_sortiej3) + diffstockj2
    diffstockj4 = Int(cherche_entrej4) + Int(cherche_sortiej4) + diffstockj3
    diffstockj5 = Int(cherche_entrej5) + Int(cherche_sortiej5) + diffstockj4
    diffstockj6 = Int(cherche_entrej6) + Int(cherche_sortiej6) + diffstockj5
    diffstockj7 = Int(cherche_entrej7) + Int(cherche_sortiej7) + diffstockj6
    diffstockj8 = Int(cherche_entrej8) + Int(cherche_sortiej8) + diffstockj7
     
     
    Sheets("PLANNING").Cells(j, 21).Value = diffstockj1
    Sheets("PLANNING").Cells(j, 22).Value = diffstockj2
    Sheets("PLANNING").Cells(j, 23).Value = diffstockj3
     
     
     
     
    'SI C EST UNE CAMPAGNE
     
    ElseIf Left(code_produit, 4) = "CAMP" Then
           numligne = Selection.Row
           For j = 37 To 500
                  If Sheets("CODE").Cells(j, 3) = Sheets("PLANNING").Cells(numligne, 4) And Sheets("CODE").Cells(j, 4) = Sheets("PLANNING").Cells(numligne, 5) And Sheets("CODE").Cells(j, 5) = Sheets("PLANNING").Cells(numligne, 6) And Left(Sheets("CODE").Cells(j, 7), 2) = Sheets("PLANNING").Cells(numligne, 7) And Sheets("CODE").Cells(j, 8) = Sheets("PLANNING").Cells(numligne, 8) Then
                     rech = Sheets("CODE").Cells(j, 1)
                     'Je récupère le code article par rapport à ma campagne
     
    'je cherche la sortie l entre et le stock de l'article s'il y a
     
    For i = 4 To 10000
            code_produit_cherche = Sheets("PDP Usine 02").Cells(i, 2)
            If Sheets("PDP Usine 02").Cells(i, 2) = "" And Sheets("PDP Usine 02").Cells(i + 1, 2) = "" And Sheets("PDP Usine 02").Cells(i + 2, 2) = "" And Sheets("PDP Usine 02").Cells(i + 3, 2) = "" And Sheets("PDP Usine 02").Cells(i + 4, 2) = "" Then
                Exit For
            Else:
                If code_produit_cherche = rech Then
                stock = Sheets("PDP Usine 02").Cells(i, 8)
                totalstock = stock + totalstock
                    If Sheets("PDP Usine 02").Cells(i + 1, 8) = "S" Then
                        cherche_sortiej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
                        cherche_sortiej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
                        cherche_sortiej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
                        cherche_sortiej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
                        cherche_sortiej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
                        cherche_sortiej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
                        cherche_sortiej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
                        cherche_sortiej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
                        total_cherche_sortiej1 = cherche_sortiej1 + total_cherche_sortiej1
                        total_cherche_sortiej2 = cherche_sortiej2 + total_cherche_sortiej2
                        total_cherche_sortiej3 = cherche_sortiej3 + total_cherche_sortiej3
                        total_cherche_sortiej4 = cherche_sortiej4 + total_cherche_sortiej4
                        total_cherche_sortiej5 = cherche_sortiej5 + total_cherche_sortiej5
                        total_cherche_sortiej6 = cherche_sortiej6 + total_cherche_sortiej6
                        total_cherche_sortiej7 = cherche_sortiej7 + total_cherche_sortiej7
                        total_cherche_sortiej8 = cherche_sortiej8 + total_cherche_sortiej8
     
                        Exit For
     
                    ElseIf Sheets("PDP Usine 02").Cells(i + 2, 8) = "S" Then
                        cherche_sortiej1 = Sheets("PDP Usine 02").Cells(i + 2, 11)
                        cherche_sortiej2 = Sheets("PDP Usine 02").Cells(i + 2, 12)
                        cherche_sortiej3 = Sheets("PDP Usine 02").Cells(i + 2, 13)
                        cherche_sortiej4 = Sheets("PDP Usine 02").Cells(i + 2, 14)
                        cherche_sortiej5 = Sheets("PDP Usine 02").Cells(i + 2, 15)
                        cherche_sortiej6 = Sheets("PDP Usine 02").Cells(i + 2, 16)
                        cherche_sortiej7 = Sheets("PDP Usine 02").Cells(i + 2, 17)
                        cherche_sortiej8 = Sheets("PDP Usine 02").Cells(i + 2, 18)
                        total_cherche_sortiej1 = cherche_sortiej1 + total_cherche_sortiej1
                        total_cherche_sortiej2 = cherche_sortiej2 + total_cherche_sortiej2
                        total_cherche_sortiej3 = cherche_sortiej3 + total_cherche_sortiej3
                        total_cherche_sortiej4 = cherche_sortiej4 + total_cherche_sortiej4
                        total_cherche_sortiej5 = cherche_sortiej5 + total_cherche_sortiej5
                        total_cherche_sortiej6 = cherche_sortiej6 + total_cherche_sortiej6
                        total_cherche_sortiej7 = cherche_sortiej7 + total_cherche_sortiej7
                        total_cherche_sortiej8 = cherche_sortiej8 + total_cherche_sortiej8
                        Exit For
     
                    ElseIf Sheets("PDP Usine 02").Cells(i + 1, 8) = "E" Then
                        cherche_entrej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
                        cherche_entrej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
                        cherche_entrej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
                        cherche_entrej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
                        cherche_entrej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
                        cherche_entrej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
                        cherche_entrej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
                        cherche_entrej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
                        total_cherche_entrej1 = cherche_entrej3 + total_cherche_entrej1
                        total_cherche_entrej2 = cherche_entrej4 + total_cherche_entrej2
                        total_cherche_entrej3 = cherche_entrej3 + total_cherche_entrej3
                        total_cherche_entrej4 = cherche_entrej4 + total_cherche_entrej4
                        total_cherche_entrej5 = cherche_entrej5 + total_cherche_entrej5
                        total_cherche_entrej6 = cherche_entrej6 + total_cherche_entrej6
                        total_cherche_entrej7 = cherche_entrej7 + total_cherche_entrej7
                        total_cherche_entrej8 = cherche_entrej8 + total_cherche_entrej8
                        Exit For
     
                    ElseIf Sheets("PDP Usine 02").Cells(i + 2, 8) = "E" Then
                        cherche_entrej1 = Sheets("PDP Usine 02").Cells(i + 2, 11)
                        cherche_entrej2 = Sheets("PDP Usine 02").Cells(i + 2, 12)
                        cherche_entrej3 = Sheets("PDP Usine 02").Cells(i + 2, 13)
                        cherche_entrej4 = Sheets("PDP Usine 02").Cells(i + 2, 14)
                        cherche_entrej5 = Sheets("PDP Usine 02").Cells(i + 2, 15)
                        cherche_entrej6 = Sheets("PDP Usine 02").Cells(i + 2, 16)
                        cherche_entrej7 = Sheets("PDP Usine 02").Cells(i + 2, 17)
                        cherche_entrej8 = Sheets("PDP Usine 02").Cells(i + 2, 18)
                        total_cherche_entrej1 = cherche_entrej3 + total_cherche_entrej1
                        total_cherche_entrej2 = cherche_entrej4 + total_cherche_entrej2
                        total_cherche_entrej3 = cherche_entrej3 + total_cherche_entrej3
                        total_cherche_entrej4 = cherche_entrej4 + total_cherche_entrej4
                        total_cherche_entrej5 = cherche_entrej5 + total_cherche_entrej5
                        total_cherche_entrej6 = cherche_entrej6 + total_cherche_entrej6
                        total_cherche_entrej7 = cherche_entrej7 + total_cherche_entrej7
                        total_cherche_entrej8 = cherche_entrej8 + total_cherche_entrej8
                        Exit For
                    Else
                        cherche_sortiej3 = 0
                    End If
                End If
            End If
    Next
     
     
    'je cherche l'entré de l'article s'il y a
     
     
    diffstockj1 = Int(total_cherche_entrej1) + Int(total_cherche_sortiej1) + Int(totalstock)
    diffstockj2 = Int(total_cherche_entrej2) + Int(total_cherche_sortiej2) + diffstockj1
    diffstockj3 = Int(total_cherche_entrej3) + Int(total_cherche_sortiej3) +  diffstockj2
    diffstockj4 = Int(total_cherche_entrej4) + Int(total_cherche_sortiej4) + diffstockj3 
    diffstockj5 = Int(total_cherche_entrej5) + Int(total_cherche_sortiej5) +  diffstockj4 
    diffstockj6 = Int(total_cherche_entrej6) + Int(total_cherche_sortiej6) +  diffstockj5 
    diffstockj7 = Int(total_cherche_entrej7) + Int(total_cherche_sortiej7) + diffstockj6 
    diffstockj8 = Int(total_cherche_entrej8) + Int(total_cherche_sortiej8) + diffstockj7 
     
     
     
    End If
    Next
    Sheets("PLANNING").Cells(j, 20).Value = stock
    Sheets("PLANNING").Cells(j, 21).Value = diffstockj1
    Sheets("PLANNING").Cells(j, 22).Value = diffstockj2
    Sheets("PLANNING").Cells(j, 23).Value = diffstockj3
    End If
     
    Application.Calculation = xlAutomatic
    End Function

  6. #6
    Rédacteur
    Avatar de Philippe Tulliez
    Homme Profil pro
    Formateur, développeur et consultant Excel, Access, Word et VBA
    Inscrit en
    Janvier 2010
    Messages
    13 182
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Formateur, développeur et consultant Excel, Access, Word et VBA

    Informations forums :
    Inscription : Janvier 2010
    Messages : 13 182
    Billets dans le blog
    53
    Par défaut
    Bonjour,
    Qu'entends-tu par
    Je ne connais pas le moyen de récupérer le numéro de ligne d'un paramètre.
    sinon pour récupérer le n° de ligne dans une plage de recherche, tu as la formule EQUIV, ce qui donne MATCH en VBA (équivalent de la traduction anglaise de la dite fonction)

    Bonjour,
    A ta place, déjà je travaillerais avec des variables dimensionnées ce serait plus lisible et plus facile à maintenir.
    En gros que fait cette fonction ?
    Philippe Tulliez
    Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément. (Nicolas Boileau)
    Lorsque vous avez la réponse à votre question, n'oubliez pas de cliquer sur et si celle-ci est pertinente pensez à voter
    Mes tutoriels : Utilisation de l'assistant « Insertion de fonction », Les filtres avancés ou élaborés dans Excel
    Mon dernier billet : Utilisation de la fonction Dir en VBA pour vérifier l'existence d'un fichier

  7. #7
    Expert confirmé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Mai 2013
    Messages
    3 609
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Canada

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Alimentation

    Informations forums :
    Inscription : Mai 2013
    Messages : 3 609
    Par défaut
    Bonjour,

    Est-ce que je me trompe ou c'est une fonction personnalisée ?
    Si c'est le cas, peut-être devrais-tu revoir ta manière de faire (?)

  8. #8
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Juin 2013
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Juin 2013
    Messages : 114
    Par défaut
    Voici le programme commenté avec quelque modification qui me permet d'avoir des calcul exact loool

    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
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    Function diffstockj8(code_produit As String)
    'declaration de toutes les variable
    Dim i As Integer
    Dim j As Integer
    Dim total_stock As Integer
    Dim stock As Integer
    Dim diffstockj1 As Integer
    Dim diffstockj2 As Integer
    Dim diffstockj3 As Integer
    Dim diffstockj4 As Integer
    Dim diffstockj5 As Integer
    Dim diffstockj6 As Integer
    Dim diffstockj7 As Integer
    Dim code_produit_cherche As String
    Dim total_cherche_sortiej1 As Integer
    Dim total_cherche_entrej1 As Integer
    Dim cherche_sortiej1 As Integer
    Dim cherche_entrej1 As Integer
    Dim cherche_sortiej2 As Integer
    Dim cherche_entrej2 As Integer
    Dim total_cherche_sortiej2 As Integer
    Dim total_cherche_entrej2 As Integer
    Dim cherche_sortiej3 As Integer
    Dim cherche_entrej3 As Integer
    Dim total_cherche_sortiej3 As Integer
    Dim total_cherche_entrej3 As Integer
    Dim cherche_sortiej4 As Integer
    Dim cherche_entrej4 As Integer
    Dim total_cherche_sortiej4 As Integer
    Dim total_cherche_entrej4 As Integer
    Dim cherche_sortiej5 As Integer
    Dim cherche_entrej5 As Integer
    Dim total_cherche_sortiej5 As Integer
    Dim total_cherche_entrej5 As Integer
    Dim cherche_sortiej6 As Integer
    Dim cherche_entrej6 As Integer
    Dim total_cherche_sortiej6 As Integer
    Dim total_cherche_entrej6 As Integer
    Dim cherche_sortiej7 As Integer
    Dim cherche_entrej7 As Integer
    Dim total_cherche_sortiej7 As Integer
    Dim total_cherche_entrej7 As Integer
    Dim cherche_sortiej8 As Integer
    Dim cherche_entrej8 As Integer
    Dim total_cherche_sortiej8 As Integer
    Dim total_cherche_entrej8 As Integer
    Dim rech As String
     
    'Ici je prend le numéro de mon paramètre même si j'aimerai le mettre en dure. Ici mon paramètre c'est B4 par exemple
    j = ActiveCell.Row
     
     
    Application.Calculation = xlManual
     
    'Je regarde si mon code produit commence par CAMP ou pas. Si c'est different de CAMP alors ma réf est un produit.
    If Left(code_produit, 4) <> "CAMP" Then
    'je cherche dans pdp usine le stock à l'instant T et les entre/sortie programmé
        For i = 4 To 10000
            code_produit_cherche = Sheets("PDP Usine 02").Cells(i, 2)
            'si les 4 ligne à la suite son nul alors je quitte la boucle puisqu'il n'y a plus rien derriere
            If Sheets("PDP Usine 02").Cells(i, 2) = "" And Sheets("PDP Usine 02").Cells(i + 1, 2) = "" And Sheets("PDP Usine 02").Cells(i + 2, 2) = "" And Sheets("PDP Usine 02").Cells(i + 3, 2) = "" And Sheets("PDP Usine 02").Cells(i + 4, 2) = "" Then
                Exit For
            Else:
     
                If code_produit_cherche = code_produit Then
                    stock = Sheets("PDP Usine 02").Cells(i, 8)
     
                    If Sheets("PDP Usine 02").Cells(i + 1, 8) = "S" Then
                        cherche_sortiej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
                        cherche_sortiej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
                        cherche_sortiej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
                        cherche_sortiej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
                        cherche_sortiej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
                        cherche_sortiej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
                        cherche_sortiej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
                        cherche_sortiej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
                      ElseIf Sheets("PDP Usine 02").Cells(i + 1, 8) = "E" Then
                        cherche_entrej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
                        cherche_entrej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
                        cherche_entrej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
                        cherche_entrej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
                        cherche_entrej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
                        cherche_entrej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
                        cherche_entrej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
                        cherche_entrej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
                    End If
     
                    If Sheets("PDP Usine 02").Cells(i + 2, 8) = "S" Then
                        cherche_sortiej1 = Sheets("PDP Usine 02").Cells(i + 2, 11)
                        cherche_sortiej2 = Sheets("PDP Usine 02").Cells(i + 2, 12)
                        cherche_sortiej3 = Sheets("PDP Usine 02").Cells(i + 2, 13)
                        cherche_sortiej4 = Sheets("PDP Usine 02").Cells(i + 2, 14)
                        cherche_sortiej5 = Sheets("PDP Usine 02").Cells(i + 2, 15)
                        cherche_sortiej6 = Sheets("PDP Usine 02").Cells(i + 2, 16)
                        cherche_sortiej7 = Sheets("PDP Usine 02").Cells(i + 2, 17)
                        cherche_sortiej8 = Sheets("PDP Usine 02").Cells(i + 2, 18)
     
     
     
                    ElseIf Sheets("PDP Usine 02").Cells(i + 2, 8) = "E" Then
                        cherche_entrej1 = Sheets("PDP Usine 02").Cells(i + 2, 11)
                        cherche_entrej2 = Sheets("PDP Usine 02").Cells(i + 2, 12)
                        cherche_entrej3 = Sheets("PDP Usine 02").Cells(i + 2, 13)
                        cherche_entrej4 = Sheets("PDP Usine 02").Cells(i + 2, 14)
                        cherche_entrej5 = Sheets("PDP Usine 02").Cells(i + 2, 15)
                        cherche_entrej6 = Sheets("PDP Usine 02").Cells(i + 2, 16)
                        cherche_entrej7 = Sheets("PDP Usine 02").Cells(i + 2, 17)
                        cherche_entrej8 = Sheets("PDP Usine 02").Cells(i + 2, 18)
                     End If
     
                   Exit For
                End If
            End If
     
        Next
    'jusqu'ici tout va bien je récupère mes valeurs et j'écrit déja mon stock
    Sheets("PLANNING").Cells(j, 20).Value = stock
    diffstockj1 = Int(cherche_entrej1) + Int(cherche_sortiej1) + Int(stock)
    diffstockj2 = Int(cherche_entrej2) + Int(cherche_sortiej2) + diffstockj1
    diffstockj3 = Int(cherche_entrej3) + Int(cherche_sortiej3) + diffstockj2
    diffstockj4 = Int(cherche_entrej4) + Int(cherche_sortiej4) + diffstockj3
    diffstockj5 = Int(cherche_entrej5) + Int(cherche_sortiej5) + diffstockj4
    diffstockj6 = Int(cherche_entrej6) + Int(cherche_sortiej6) + diffstockj5
    diffstockj7 = Int(cherche_entrej7) + Int(cherche_sortiej7) + diffstockj6
     
     
    ' une fois mes calculs fait j'écrit dans les case correspondante mes valeurs et ma fonction me renvoie diffstock8
    Sheets("PLANNING").Cells(j, 21).Value = diffstockj1
    Sheets("PLANNING").Cells(j, 22).Value = diffstockj2
    Sheets("PLANNING").Cells(j, 23).Value = diffstockj3
    diffstockj8 = Int(cherche_entrej8) + Int(cherche_sortiej8) + diffstockj7
     
     
     
    'SI C EST UNE CAMPAGNE je vais venir récupérer les codes article correspondant puis je vais faire la même chose que ci dessus
     
    ElseIf Left(code_produit, 4) = "CAMP" Then
           numligne = Selection.Row
           For j = 37 To 500
                  If Sheets("CODE").Cells(j, 3) = Sheets("PLANNING").Cells(numligne, 4) And Sheets("CODE").Cells(j, 4) = Sheets("PLANNING").Cells(numligne, 5) And Sheets("CODE").Cells(j, 5) = Sheets("PLANNING").Cells(numligne, 6) And Left(Sheets("CODE").Cells(j, 7), 2) = Sheets("PLANNING").Cells(numligne, 7) And Sheets("CODE").Cells(j, 8) = Sheets("PLANNING").Cells(numligne, 8) Then
                     rech = Sheets("CODE").Cells(j, 1)
                     'Je récupère le code article par rapport à ma campagne
     
    'je cherche la sortie l entre et le stock de l'article s'il y a
     
    For i = 4 To 10000
            code_produit_cherche = Sheets("PDP Usine 02").Cells(i, 2)
            If Sheets("PDP Usine 02").Cells(i, 2) = "" And Sheets("PDP Usine 02").Cells(i + 1, 2) = "" And Sheets("PDP Usine 02").Cells(i + 2, 2) = "" And Sheets("PDP Usine 02").Cells(i + 3, 2) = "" And Sheets("PDP Usine 02").Cells(i + 4, 2) = "" Then
                Exit For
            Else:
                If code_produit_cherche = rech Then
                stock = Sheets("PDP Usine 02").Cells(i, 8)
                totalstock = stock + totalstock
                If Sheets("PDP Usine 02").Cells(i + 1, 8) = "S" Then
                        cherche_sortiej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
                        cherche_sortiej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
                        cherche_sortiej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
                        cherche_sortiej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
                        cherche_sortiej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
                        cherche_sortiej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
                        cherche_sortiej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
                        cherche_sortiej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
                        total_cherche_sortiej1 = cherche_sortiej1 + total_cherche_sortiej1
                        total_cherche_sortiej2 = cherche_sortiej2 + total_cherche_sortiej2
                        total_cherche_sortiej3 = cherche_sortiej3 + total_cherche_sortiej3
                        total_cherche_sortiej4 = cherche_sortiej4 + total_cherche_sortiej4
                        total_cherche_sortiej5 = cherche_sortiej5 + total_cherche_sortiej5
                        total_cherche_sortiej6 = cherche_sortiej6 + total_cherche_sortiej6
                        total_cherche_sortiej7 = cherche_sortiej7 + total_cherche_sortiej7
                        total_cherche_sortiej8 = cherche_sortiej8 + total_cherche_sortiej8
     
                ElseIf Sheets("PDP Usine 02").Cells(i + 1, 8) = "E" Then
                        cherche_entrej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
                        cherche_entrej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
                        cherche_entrej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
                        cherche_entrej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
                        cherche_entrej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
                        cherche_entrej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
                        cherche_entrej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
                        cherche_entrej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
                        total_cherche_entrej1 = cherche_entrej3 + total_cherche_entrej1
                        total_cherche_entrej2 = cherche_entrej4 + total_cherche_entrej2
                        total_cherche_entrej3 = cherche_entrej3 + total_cherche_entrej3
                        total_cherche_entrej4 = cherche_entrej4 + total_cherche_entrej4
                        total_cherche_entrej5 = cherche_entrej5 + total_cherche_entrej5
                        total_cherche_entrej6 = cherche_entrej6 + total_cherche_entrej6
                        total_cherche_entrej7 = cherche_entrej7 + total_cherche_entrej7
                        total_cherche_entrej8 = cherche_entrej8 + total_cherche_entrej8
                  End If
     
                  If Sheets("PDP Usine 02").Cells(i + 2, 8) = "S" Then
                        cherche_sortiej1 = Sheets("PDP Usine 02").Cells(i + 2, 11)
                        cherche_sortiej2 = Sheets("PDP Usine 02").Cells(i + 2, 12)
                        cherche_sortiej3 = Sheets("PDP Usine 02").Cells(i + 2, 13)
                        cherche_sortiej4 = Sheets("PDP Usine 02").Cells(i + 2, 14)
                        cherche_sortiej5 = Sheets("PDP Usine 02").Cells(i + 2, 15)
                        cherche_sortiej6 = Sheets("PDP Usine 02").Cells(i + 2, 16)
                        cherche_sortiej7 = Sheets("PDP Usine 02").Cells(i + 2, 17)
                        cherche_sortiej8 = Sheets("PDP Usine 02").Cells(i + 2, 18)
                        total_cherche_sortiej1 = cherche_sortiej1 + total_cherche_sortiej1
                        total_cherche_sortiej2 = cherche_sortiej2 + total_cherche_sortiej2
                        total_cherche_sortiej3 = cherche_sortiej3 + total_cherche_sortiej3
                        total_cherche_sortiej4 = cherche_sortiej4 + total_cherche_sortiej4
                        total_cherche_sortiej5 = cherche_sortiej5 + total_cherche_sortiej5
                        total_cherche_sortiej6 = cherche_sortiej6 + total_cherche_sortiej6
                        total_cherche_sortiej7 = cherche_sortiej7 + total_cherche_sortiej7
                        total_cherche_sortiej8 = cherche_sortiej8 + total_cherche_sortiej8
     
     
     
     
     
                    ElseIf Sheets("PDP Usine 02").Cells(i + 2, 8) = "E" Then
                        cherche_entrej1 = Sheets("PDP Usine 02").Cells(i + 2, 11)
                        cherche_entrej2 = Sheets("PDP Usine 02").Cells(i + 2, 12)
                        cherche_entrej3 = Sheets("PDP Usine 02").Cells(i + 2, 13)
                        cherche_entrej4 = Sheets("PDP Usine 02").Cells(i + 2, 14)
                        cherche_entrej5 = Sheets("PDP Usine 02").Cells(i + 2, 15)
                        cherche_entrej6 = Sheets("PDP Usine 02").Cells(i + 2, 16)
                        cherche_entrej7 = Sheets("PDP Usine 02").Cells(i + 2, 17)
                        cherche_entrej8 = Sheets("PDP Usine 02").Cells(i + 2, 18)
                        total_cherche_entrej1 = cherche_entrej3 + total_cherche_entrej1
                        total_cherche_entrej2 = cherche_entrej4 + total_cherche_entrej2
                        total_cherche_entrej3 = cherche_entrej3 + total_cherche_entrej3
                        total_cherche_entrej4 = cherche_entrej4 + total_cherche_entrej4
                        total_cherche_entrej5 = cherche_entrej5 + total_cherche_entrej5
                        total_cherche_entrej6 = cherche_entrej6 + total_cherche_entrej6
                        total_cherche_entrej7 = cherche_entrej7 + total_cherche_entrej7
                        total_cherche_entrej8 = cherche_entrej8 + total_cherche_entrej8
                    End If
                  Exit For
                End If
            End If
    Next
     
     
    'je fais mes calculs
     
     
    diffstockj1 = Int(total_cherche_entrej1) + Int(total_cherche_sortiej1) + Int(totalstock)
    diffstockj2 = Int(total_cherche_entrej2) + Int(total_cherche_sortiej2) + diffstockj1
    diffstockj3 = Int(total_cherche_entrej3) + Int(total_cherche_sortiej3) + diffstockj2
    diffstockj4 = Int(total_cherche_entrej4) + Int(total_cherche_sortiej4) + diffstockj3
    diffstockj5 = Int(total_cherche_entrej5) + Int(total_cherche_sortiej5) + diffstockj4
    diffstockj6 = Int(total_cherche_entrej6) + Int(total_cherche_sortiej6) + diffstockj5
    diffstockj7 = Int(total_cherche_entrej7) + Int(total_cherche_sortiej7) + diffstockj6
     
     
     
    End If
    Next
    Sheets("PLANNING").Cells(j, 20).Value = stock
    Sheets("PLANNING").Cells(j, 21).Value = diffstockj1
    Sheets("PLANNING").Cells(j, 22).Value = diffstockj2
    Sheets("PLANNING").Cells(j, 23).Value = diffstockj3
    diffstockj8 = Int(total_cherche_entrej8) + Int(total_cherche_sortiej8) + diffstockj7
    End If
     
    Application.Calculation = xlAutomatic
    End Function
    Pour mon j, au lieu de faire , j'aurai aimé le mettre en dure comme mais ca ne marche pas.

  9. #9
    Rédacteur
    Avatar de Philippe Tulliez
    Homme Profil pro
    Formateur, développeur et consultant Excel, Access, Word et VBA
    Inscrit en
    Janvier 2010
    Messages
    13 182
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Formateur, développeur et consultant Excel, Access, Word et VBA

    Informations forums :
    Inscription : Janvier 2010
    Messages : 13 182
    Billets dans le blog
    53
    Par défaut
    Bonjour,
    Je ne voudrais pas insister mais très sincèrement en expliquant clairement ce que ta fonction fait et en utilisant les variables dimensionnées cela se réduirait sans doute à maximum 15 lignes.
    Philippe Tulliez
    Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément. (Nicolas Boileau)
    Lorsque vous avez la réponse à votre question, n'oubliez pas de cliquer sur et si celle-ci est pertinente pensez à voter
    Mes tutoriels : Utilisation de l'assistant « Insertion de fonction », Les filtres avancés ou élaborés dans Excel
    Mon dernier billet : Utilisation de la fonction Dir en VBA pour vérifier l'existence d'un fichier

  10. #10
    Membre confirmé
    Homme Profil pro
    Inscrit en
    Juin 2013
    Messages
    114
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Secteur : Communication - Médias

    Informations forums :
    Inscription : Juin 2013
    Messages : 114
    Par défaut
    oui c'est une fonction personnalisé. Au lieu de tous mettre à la suite j'avais une boucle pour stockdiff1, une pour stockdiff2, une pour stockdiff3...
    Bref et je me suis aperçu que dans une boucle je peux récupérer toutes les informations que je voulais... Avec le débug, je vois que je récupère les bonnes informations le problème viens du faites que je n'arrive pas à écrire les données récupérées.

    M'en voulez pas, je développe à la base en php et non pas en VBA. Je suis nouveau dans ce domaine... J'en apprends tous les jours grâce au tuto et grâce à vous tous... Merci beaucoup de votre aide.
    Revoir ma facon de faire... Explique

    Je suis désolé mais les variable dimensionnés je ne connais pas...
    Tu ne comprends pas ce que fais mon programme? Avec mes commentaires non plus?

    Ma fonction récupère le stock, les entrés et les sorties qui sont affiché dans ma page "PDP 02 Usine".
    Si je mets un code article, il va directement rechercher le stock, les entrés et sorties de mon article en question.
    Si c'est une campagne, (campagne = X articles), je dois trouver dans un premier temps mes codes articles et trouver les stocks, entrés et sorties du produit.

    Ai je été clair... Croyez moi ce n'est pas mon but de ne pas être clair

  11. #11
    Rédacteur
    Avatar de Philippe Tulliez
    Homme Profil pro
    Formateur, développeur et consultant Excel, Access, Word et VBA
    Inscrit en
    Janvier 2010
    Messages
    13 182
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Formateur, développeur et consultant Excel, Access, Word et VBA

    Informations forums :
    Inscription : Janvier 2010
    Messages : 13 182
    Billets dans le blog
    53
    Par défaut
    Bonjour,
    Un petit exemple de réduction de lignes en utilisant des variables dimensionnées
    J'ai pris tes lignes de code de 68 à 86
    Soit
    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
     If Sheets("PDP Usine 02").Cells(i + 1, 8) = "S" Then
        cherche_sortiej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
        cherche_sortiej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
        cherche_sortiej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
        cherche_sortiej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
        cherche_sortiej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
        cherche_sortiej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
        cherche_sortiej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
        cherche_sortiej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
      ElseIf Sheets("PDP Usine 02").Cells(i + 1, 8) = "E" Then
        cherche_entrej1 = Sheets("PDP Usine 02").Cells(i + 1, 11)
        cherche_entrej2 = Sheets("PDP Usine 02").Cells(i + 1, 12)
        cherche_entrej3 = Sheets("PDP Usine 02").Cells(i + 1, 13)
        cherche_entrej4 = Sheets("PDP Usine 02").Cells(i + 1, 14)
        cherche_entrej5 = Sheets("PDP Usine 02").Cells(i + 1, 15)
        cherche_entrej6 = Sheets("PDP Usine 02").Cells(i + 1, 16)
        cherche_entrej7 = Sheets("PDP Usine 02").Cells(i + 1, 17)
        cherche_entrej8 = Sheets("PDP Usine 02").Cells(i + 1, 18)
      End If
    Qui se réduisent à ceci
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     If Sheets("PDP Usine 02").Cells(i + 1, 8) = "S" Then
        For c = 1 To 8
         Cherche_SortieJ(c) = Sheets("PDP Usine 02").Cells(i + 1, c + 10)
        Next
      ElseIf Sheets("PDP Usine 02").Cells(i + 1, 8) = "E" Then
        For c = 1 To 8
         Cherche_EntreeJ(c) = Sheets("PDP Usine 02").Cells(i + 1, c + 10)
        Next
      End If
    donc la déclaration des variables est réduite aussi de 16 à 2 lignes
    Au lieu de ces 2 lignes multipliées par 8
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Dim cherche_sortiej1 As Integer
    Dim cherche_entrej1 As Integer
    Voici à quoi se résume la déclaration des variables dimensionnées
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Dim Cherche_SortieJ(1 To 8) As Integer, Cherche_EntreeJ(1 To 8) As Integer
    Et bien entendu il y a les autres variables Total, Différence etc...

    Je te suggère donc la lecture de ce tutoriel Utiliser les variables tableaux en VBA Excel et l'incontournable pour comprendre la conceptualisation des tableaux de Didier Gonard

    Petites remarques supplémentaires
    J'utiliserais aussi des variables string pour placer le nom des feuilles en début de procédure et mieux encore des variables objets. Cela facilite grandement la lisibilité de ton code et surtout la maintenance.

    Je n'ai pas compris le ElseIf dans ce code. A part E & S en colonne 8 y a-t-il d'autres codes ? sinon un simple If Then Else aurait suffit.
    Pour ma part une entrée est positive et une sortie négative donc pour la gestion des stock, je n'utilise qu'une seule colonne le signe m'indiquant si c'est une sortie ou une entrée.
    Philippe Tulliez
    Ce que l'on conçoit bien s'énonce clairement, et les mots pour le dire arrivent aisément. (Nicolas Boileau)
    Lorsque vous avez la réponse à votre question, n'oubliez pas de cliquer sur et si celle-ci est pertinente pensez à voter
    Mes tutoriels : Utilisation de l'assistant « Insertion de fonction », Les filtres avancés ou élaborés dans Excel
    Mon dernier billet : Utilisation de la fonction Dir en VBA pour vérifier l'existence d'un fichier

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Optimisation C++] Calcul code altitude
    Par Spout dans le forum C++
    Réponses: 7
    Dernier message: 13/11/2007, 23h17
  2. Optimisation du calcul de la feuille
    Par saipas dans le forum Macros et VBA Excel
    Réponses: 10
    Dernier message: 22/08/2007, 15h22
  3. optimisation de calcul de boite englobante
    Par Rastacouéne dans le forum Mathématiques
    Réponses: 7
    Dernier message: 25/04/2007, 15h32
  4. Optimiser un calcul avec parcours de recordset
    Par hugo69 dans le forum Access
    Réponses: 28
    Dernier message: 12/06/2006, 11h37
  5. [Optimisation][Fonction]calcul du nombre de jours ...
    Par m-mas dans le forum MS SQL Server
    Réponses: 6
    Dernier message: 26/10/2005, 15h39

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo