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 :

Simplication Macro avec "Case"


Sujet :

Macros et VBA Excel

Mode arborescent

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Avril 2009
    Messages
    22
    Détails du profil
    Informations forums :
    Inscription : Avril 2009
    Messages : 22
    Par défaut Simplication Macro avec "Case"
    Bonjour,

    je souhaiterais simplifier la macro ci dessous afin de gagner en temps de calcul. Je vous ai mis le fichier en pièce jointe.

    j'ai un calcul à faire en fonction du type de ces éléments ci dessous:

    ROUTEUR
    ANNEAU
    BRASSEUR
    BAS
    ASBC
    MGW
    RTC
    VOD

    Je fais des boucles "if" à chaque fois et cela alourdit le temps. Y aurais-t-il un moyen pour simplifier cette macro ?

    Merci d'avance pour votre aide



    -------------------------------------------------------------------------


    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
    Sub suivi_charge_perspective()
     
    Dim Lg As Long
    Dim LgDer As Long
    Dim ClDer As Long
    Dim I As Long
    Dim J As Long
     
     
    Sheets("Suivi_charge_ingenieristes").Select
     
      LgDer = Range("A65536").End(xlUp).Row
      fin = Range("A" & Cells.Rows.Count).End(xlUp).Row
      ClDer = Range("IV1").End(xlToLeft).Column
     
        Range("BD4:CR600").Select
        Selection.ClearContents
     
      Date_MAD_souhaite = 12
      Operation = 54
     
      For I = 4 To fin
        For J = 56 To 96
     
            If Cells(I, Operation) = "ROUTEUR" Then
     
            If CDate(Cells(I, Date_MAD_souhaite)) >= CDate(Cells(1, J)) And CDate(Cells(I, Date_MAD_souhaite)) <= CDate(Cells(2, J)) Then
             Cells(I, J) = 1
            toto = J - 3
            If toto < 56 Then toto = 56
            Range(Cells(I, 56), Cells(I, toto)) = ""
            Range(Cells(I, toto), Cells(I, J)) = 1
     
     
        End If
    '.........................
        End If
     
            If Cells(I, Operation) = "ANNEAU" Then
     
            If CDate(Cells(I, Date_MAD_souhaite)) >= CDate(Cells(1, J)) And CDate(Cells(I, Date_MAD_souhaite)) <= CDate(Cells(2, J)) Then
             Cells(I, J) = 1
            toto = J - 5
            If toto < 56 Then toto = 56
            Range(Cells(I, 56), Cells(I, toto)) = ""
            Range(Cells(I, toto), Cells(I, J)) = 0.5
     
     
        End If
    '.........................
     
        End If
     
     
            If Cells(I, Operation) = "WDM" Then
     
            If CDate(Cells(I, Date_MAD_souhaite)) >= CDate(Cells(1, J)) And CDate(Cells(I, Date_MAD_souhaite)) <= CDate(Cells(2, J)) Then
             Cells(I, J) = 1
            toto = J - 5
            If toto < 56 Then toto = 56
            Range(Cells(I, 56), Cells(I, toto)) = ""
            Range(Cells(I, toto), Cells(I, J)) = 1
     
     
        End If
    '.........................
     
        End If
     
     
            If Cells(I, Operation) = "BRASSEUR" Then
     
            If CDate(Cells(I, Date_MAD_souhaite)) >= CDate(Cells(1, J)) And CDate(Cells(I, Date_MAD_souhaite)) <= CDate(Cells(2, J)) Then
             Cells(I, J) = 1
            toto = J - 4
            If toto < 56 Then toto = 56
            Range(Cells(I, 56), Cells(I, toto)) = ""
            Range(Cells(I, toto), Cells(I, J)) = 1
     
     
        End If
     '.........................
        End If
     
     
            If Cells(I, Operation) = "BAS" Then
     
            If CDate(Cells(I, Date_MAD_souhaite)) >= CDate(Cells(1, J)) And CDate(Cells(I, Date_MAD_souhaite)) <= CDate(Cells(2, J)) Then
             Cells(I, J) = 1
            toto = J - 4
            If toto < 56 Then toto = 56
            Range(Cells(I, 56), Cells(I, toto)) = ""
            Range(Cells(I, toto), Cells(I, J)) = 1
     
     
        End If
    '.........................
        End If
     
     
            If Cells(I, Operation) = "ASBC" Then
     
            If CDate(Cells(I, Date_MAD_souhaite)) >= CDate(Cells(1, J)) And CDate(Cells(I, Date_MAD_souhaite)) <= CDate(Cells(2, J)) Then
             Cells(I, J) = 1
            toto = J - 4
            If toto < 56 Then toto = 56
            Range(Cells(I, 56), Cells(I, toto)) = ""
            Range(Cells(I, toto), Cells(I, J)) = 1
     
     
        End If
    '.........................
        End If
     
     
            If Cells(I, Operation) = "RTC" Then
     
            If CDate(Cells(I, Date_MAD_souhaite)) >= CDate(Cells(1, J)) And CDate(Cells(I, Date_MAD_souhaite)) <= CDate(Cells(2, J)) Then
             Cells(I, J) = 1
            toto = J - 2
            If toto < 56 Then toto = 56
            Range(Cells(I, 56), Cells(I, toto)) = ""
            Range(Cells(I, toto), Cells(I, J)) = 1
     
     
        End If
     
    '.........................
        End If
     
     
            If Cells(I, Operation) = "VOD" Then
     
            If CDate(Cells(I, Date_MAD_souhaite)) >= CDate(Cells(1, J)) And CDate(Cells(I, Date_MAD_souhaite)) <= CDate(Cells(2, J)) Then
             Cells(I, J) = 1
            toto = J - 3
            If toto < 56 Then toto = 56
            Range(Cells(I, 56), Cells(I, toto)) = ""
            Range(Cells(I, toto), Cells(I, J)) = 1
     
     
        End If
     
    '.........................
        End If
     
     
            If Cells(I, Operation) = "MGW" Then
     
            If CDate(Cells(I, Date_MAD_souhaite)) >= CDate(Cells(1, J)) And CDate(Cells(I, Date_MAD_souhaite)) <= CDate(Cells(2, J)) Then
             Cells(I, J) = 1
            toto = J - 2
            If toto < 56 Then toto = 56
            Range(Cells(I, 56), Cells(I, toto)) = ""
            Range(Cells(I, toto), Cells(I, J)) = 1
     
     
        End If
     
        End If
     
     
     
        Next J
      Next I
     
      MsgBox ("Calcul Terminé")
     
     
    End Sub
    Fichiers attachés Fichiers attachés

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

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