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 :

Ecouter un evenement sur une cellule et le reproduire sur une autre cellule


Sujet :

Macros et VBA Excel

  1. #1
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut Ecouter un evenement sur une cellule et le reproduire sur une autre cellule
    Bonjour,

    J'ai cherché brievement et je n'ai pas trouvé grand chose de concluant, mes connaissances en vba n'arrangeant rien ...

    J'aurais besoin d'écouter sur plusieurs cellules d'une feuille excel un changement de couleur et de répercuter ce changement de couleur sur d'autres cellules se trouvant sur d'autres feuilles.

    J'ai trouvé ce code sur votre site mais je ne sais pas comment l'utiliser ...

    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
    Option Explicit 
     
    Dim x As Integer 
    Dim Cell As String 
     
     
     
    Private Sub Worksheet_Activate() 
            x = ActiveCell.Interior.ColorIndex 
            Cell = ActiveCell.Address 
    End Sub 
     
     
     
    Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
        On Error Resume Next 
     
        If Cell = "" Then 
            x = Target.Interior.ColorIndex 
            Cell = Target.Address 
            Exit Sub 
        End If 
     
        If Range(Cell).Interior.ColorIndex <> x Then _ 
            MsgBox "la couleur de la cellule " & Cell & " a changé" 
     
        x = Target.Interior.ColorIndex 
        Cell = Target.Address 
    End Sub
    Merci à vous !
    Kulnae.

  2. #2
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    Ce code permet de changer la couleur d'une case quand on en modifie une deuxième

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Private Sub Worksheet_change(ByVal target As Range)
     
    If target.adress = range("Ta case").adress Then
    x=target.interior.colorindex
    range("la case à modifier en même temps").interior.colorindex=x
    End If
     
    end sub

  3. #3
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    Pour ecouter plusieurs cellule tu peux faire la même chose

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    Private Sub Worksheet_change(ByVal target As Range)
    Select Case target.adress
    Case range("A1").adress
    x=target.interior.colorindex
    range("la case à modifier en même temps").interior.colorindex=x
    Case range("A2").adress
    x=target.interior.colorindex
    range("la case à modifier en même temps").interior.colorindex=x
    ...
    End Select
    end sub
    Si les cases à changer sont toujours placées par exemple 2 case plus loin que la case écoutée tu peux condenser ça sur une ligne.
    Si toutes les cases à écouter sont sur une colonne:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    Private Sub Worksheet_change(ByVal target As Range)
    if target.column=1 'pour ecouter la colonne 1 par exemple
    x=target.interior.colorindex
    cells(target.rows,target.column+2).interior.colorindex=x
    end if
    end sub

  4. #4
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut
    Merci à toi diude !

    Mais j'aimerais savoir, comment faire pour une fois cette macro créer, la "faire marcher" ? L'appliquer aux cellules pour qu'elle joue son rôle ?

    Merci.

  5. #5
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    Tu ouvre l'editeur visual basic et tu place le code dans ta feuille.
    Ex Dans feuil1 si c'est sur cette feuille...
    Pour ouvrir l'editeur tu va dans outils=> macro=>visual basic editor

  6. #6
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut
    Bonjour,

    Tu ouvre l'editeur visual basic et tu place le code dans ta feuille.
    Ex Dans feuil1 si c'est sur cette feuille...
    Merci de tes réponses diude mais je n'ai toujours pas compris comment faire ...

    Comment je "place" le code dans la feuille ?
    Une macro sur un fichier objet image je sais le faire, mais ça non ...

    Sinon, voilà mon code largement inspiré de ton code. Qu'en penses-tu ?

    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
    Private Sub Worksheet_change(ByVal target As Range)
     
    Select Case target.adress
     
    Case Range("B7").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B7").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD1").Tab.ColorIndex = x
    End If
     
    Case Range("B8").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B8").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD2").Tab.ColorIndex = x
    End If
     
    Case Range("B9").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B9").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD3").Tab.ColorIndex = x
    End If
     
    Case Range("B10").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B10").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD4").Tab.ColorIndex = x
    End If
     
    Case Range("B11").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B11").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD5").Tab.ColorIndex = x
    End If
     
    Case Range("B12").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B12").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD6").Tab.ColorIndex = x
    End If
     
    Case Range("B13").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B13").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD7").Tab.ColorIndex = x
    End If
     
    Case Range("B14").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B14").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD8").Tab.ColorIndex = x
    End If
     
    Case Range("B15").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B15").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD9").Tab.ColorIndex = x
    End If
     
    Case Range("B16").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B16").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD10").Tab.ColorIndex = x
    End If
     
    Case Range("B17").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B17").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD11").Tab.ColorIndex = x
    End If
     
    Case Range("B18").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B18").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD12").Tab.ColorIndex = x
    End If
     
    Case Range("B19").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B19").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD13").Tab.ColorIndex = x
    End If
     
    Case Range("B20").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B20").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD14").Tab.ColorIndex = x
    End If
     
    Case Range("B21").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B21").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD15").Tab.ColorIndex = x
    End If
     
    Case Range("B22").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B22").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD16").Tab.ColorIndex = x
    End If
     
    Case Range("B23").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B23").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD17").Tab.ColorIndex = x
    End If
     
    Case Range("B24").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B24").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD18").Tab.ColorIndex = x
    End If
     
    Case Range("B25").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B25").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD19").Tab.ColorIndex = x
    End If
     
    Case Range("B26").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B26").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD20").Tab.ColorIndex = x
    End If
     
    Case Range("B29").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B27").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD21").Tab.ColorIndex = x
    End If
     
    Case Range("B30").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B28").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD22").Tab.ColorIndex = x
    End If
     
    Case Range("B31").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B29").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD23").Tab.ColorIndex = x
    End If
     
    Case Range("B32").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B30").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD24").Tab.ColorIndex = x
    End If
     
    Case Range("B33").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B31").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD25").Tab.ColorIndex = x
    End If
     
    Case Range("B34").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B32").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD26").Tab.ColorIndex = x
    End If
     
    Case Range("B35").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B33").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD27").Tab.ColorIndex = x
    End If
     
    Case Range("B36").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B34").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD28").Tab.ColorIndex = x
    End If
     
    Case Range("B37").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B35").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD29").Tab.ColorIndex = x
    End If
     
    Case Range("B38").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B36").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD30").Tab.ColorIndex = x
    End If
     
    Case Range("B39").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B37").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD31").Tab.ColorIndex = x
    End If
     
    Case Range("B42").adress
    x = target.Interior.ColorIndex
    If x = 16 Then Range("'FI'!B38").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD32").Tab.ColorIndex = x
    End If
     
    End Select
    End Sub
    Merci !
    Kulnae.

  7. #7
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    Je te met un fichier ou j'ai placé le code au bon endroit.
    J'ai corigé des erreurs dans ton code.
    Il en reste mais je te laisse les corriger :
    quand tu veux colorier les cellule, tu as mis:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Range("'FI'!B7").Interior.ColorIndex = x
    or Range("'FI'!B7") est faux.

    La syntaxe est

    ou equivalent si tu veux utiliser les numeros de ligne et de colonne:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    range(cells(1,1),cells(1,10))
    Le fichier que je t'ai donné fonctionne pour la ligne 16, si tu change la valeur de la case B16 la case C16 sera coloriée et l'onglet également.
    Pour voir le code ouvre visual basic editor, regarde dans microsoft object=> Feuil1

  8. #8
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut
    Ok je vois comment ça marche maintenant (pas totalement) ! Je comprends pourquoi mon code Range("'FI'!B7") (par exemple) ne marche pas !

    Merci beaucoup !

    Cependant, j'ai encore un soucis ...
    Comment ta macro ecoute1 marche-t'elle ? Tu peux la créer ainsi et ne l'affecter à rien, elle marchera toute seule quand même ?

    ET

    Comment faire pour modifier la couleur d'autres cases, à adresses différentes, sur d'autres feuilles excel ?

    Je pense que le problème vient de là : (ton code)
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ActiveWorkbook.Sheets("MDD10").Tab.ColorIndex = x
    Mais justement je ne comprends pas où se trouve le code qui dit à excel de colorier ta case C16 ... D'ailleurs j'ai beau changer la couleur de la case B16, rien ne change ...

    Merci !
    Kulnae.

  9. #9
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    Cette macro:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Private Sub Worksheet_change(ByVal target As Range)
     
    Sub
    S'execute à chaque changement d'une valeur d'une case excel dans la feuille.
    Donc oui il suffit de la laisser comme ça et elle s'execute toute seule.
    Maintenant elle ne se déclenche pas si on change uniquement la couleur d'une case mais bien si on change la valeur qui est dans la case. Même si on change la valeur pour la même. En fait elle se lance à chaque saisie. Donc si tu saisi quelque chose en B16 tu verras la cellule C16 changer de couleure.

    Ensuite le
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    ActiveWorkbook.Sheets("MDD10").Tab.ColorIndex = x
    sert à mettre en couleur l'onglet de la feuille et non pas une cellule de la feuille.
    Pour mettre en couleur une cellule de la feuille il faut faire:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Thisworbook.Sheets("ta feuille").Range("Ta case").interior.colorindex=x
    Enfin c'est la partie:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
     Range("'C16").Interior.ColorIndex =x
    qui permet de mettre en couleur la case C16.

    Sinon pour executer la macro si tu change juste la couleur de la case je ne vois pas trop.

    Si ta feuille est selectionnée, si c'est celle active tu peux t'affranchir de
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Thisworbokk.Sheets("ta feuille").
    et mettre directement

  10. #10
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut
    Bonsoir,

    Finalement me revoilà ! ^^

    Alors 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
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
     
    x = ActiveCell.Interior.ColorIndex
     
    Select Case Target.adress
     
    Case Range("B7").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B7:L7").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD1").Tab.ColorIndex = x
     
    Case Range("B8").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B8:L8").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD2").Tab.ColorIndex = x
     
    Case Range("B9").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B9:L9").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD3").Tab.ColorIndex = x
     
    Case Range("B10").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B10:L10").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD4").Tab.ColorIndex = x
     
    Case Range("B11").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B11:L11").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD5").Tab.ColorIndex = x
     
    Case Range("B12").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B12:L12").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD6").Tab.ColorIndex = x
     
    Case Range("B13").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B13:L13").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD7").Tab.ColorIndex = x
     
    Case Range("B14").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B14:L14").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD8").Tab.ColorIndex = x
     
    Case Range("B15").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B15:L15").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD9").Tab.ColorIndex = x
     
    Case Range("B16").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B16:L16").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD10").Tab.ColorIndex = x
     
    Case Range("B17").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B17:L17").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD11").Tab.ColorIndex = x
     
    Case Range("B18").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B18:L18").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD12").Tab.ColorIndex = x
     
    Case Range("B19").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B19:L19").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD13").Tab.ColorIndex = x
     
     
    Case Range("B20").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B20:L20").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD14").Tab.ColorIndex = x
     
     
    Case Range("B21").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B21:L21").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD15").Tab.ColorIndex = x
     
     
    Case Range("B22").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B22:L22").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD16").Tab.ColorIndex = x
     
     
    Case Range("B23").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B23:L23").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD17").Tab.ColorIndex = x
     
     
    Case Range("B24").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B24:L24").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD18").Tab.ColorIndex = x
     
     
    Case Range("B25").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B25:L25").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD19").Tab.ColorIndex = x
     
     
    Case Range("B26").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B26:L26").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD20").Tab.ColorIndex = x
     
     
    Case Range("B29").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B27:L27").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD21").Tab.ColorIndex = x
     
     
    Case Range("B30").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B28:L28").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD22").Tab.ColorIndex = x
     
     
    Case Range("B31").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B29:L29").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD23").Tab.ColorIndex = x
     
     
    Case Range("B32").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B30:L30").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD24").Tab.ColorIndex = x
     
     
    Case Range("B33").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B31:L31").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD25").Tab.ColorIndex = x
     
     
    Case Range("B34").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B32:L32").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD26").Tab.ColorIndex = x
     
     
    Case Range("B35").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B33:L33").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD27").Tab.ColorIndex = x
     
     
    Case Range("B36").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B34:L34").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD28").Tab.ColorIndex = x
     
     
    Case Range("B37").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B35:L35").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD29").Tab.ColorIndex = x
     
     
    Case Range("B38").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B36:L36").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD30").Tab.ColorIndex = x
     
     
    Case Range("B39").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B37:L37").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD31").Tab.ColorIndex = x
     
     
    Case Range("B42").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B38:L38").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD32").Tab.ColorIndex = x
     
     
    End Select
    End Sub
    Ps. : Dans le code ci-dessus, la première ligne apparaît en jaune surligné ...


    J'ai donc fais les changements que tu m'as conseillés et j'ai supprimé les End If car erreur de compilation (pas de bloc if ...).

    Le code ne marche pas ...
    Je pense que c'est comme tu as dis il faut apporter un changement dans la cellule en elle même...

    Mais j'ai essayé sans succès de passer par Worksheet_Activate() comme dans le tuto ...

    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
    Option Explicit 
     
    Dim x As Integer 
    Dim Cell As String 
     
     
     
    Private Sub Worksheet_Activate() 
            x = ActiveCell.Interior.ColorIndex 
            Cell = ActiveCell.Address 
    End Sub 
     
     
     
    Private Sub Worksheet_SelectionChange(ByVal Target As Range) 
        On Error Resume Next 
     
        If Cell = "" Then 
            x = Target.Interior.ColorIndex 
            Cell = Target.Address 
            Exit Sub 
        End If 
     
        If Range(Cell).Interior.ColorIndex <> x Then _ 
            MsgBox "la couleur de la cellule " & Cell & " a changé" 
     
        x = Target.Interior.ColorIndex 
        Cell = Target.Address 
    End Sub
    Je rappelle mon but : lorsque l'utilisateur modifie la couleur de fond d'une cellule se trouvant sur une feuille de calcul appelée "FD-MDD", il faut que le excel aille tout seul modifier la couleur d'une feuille de calcul correspondant à la cellulle (les noms des cellules sont MDDx) et la couleur de fond d'une cellule sur une AUTRE feuille de calcul appellée "FI".

    J'aurais bien besoin d'aide car là ça coince

    Merci !

  11. #11
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    En effet une solution consiste à mettre un code dans worksheet activate. Le changement de couleur ne se fera pas immediatement mais à l'activation de la feuille:

    Tu es sur la feuille de calcul "FD-MDD", tu change de couleur une case.
    Ensuite tu vas sur la feuille corespondant à la case que tu viens de modifier, à ce moment le code de worksheet activate se lance et vient changer la couleur des cases dans cette feuille.

    Maintenant si tu veux changer uniquement la couleur de l'onglet de la feuille qui porte le même nom que la case, alors cette technique marchera mais tant que tu n'aura pas activé l'onglet la couleur ne changera pas.
    Sinon une solution simple serai de mettre un bouton dans la feuille "FD-MDD" qui pourrai s'appeler mise à jour des couleurs ou un truc du genre et qui permettrai de lancer la macro pour faire les changements de couleur.


    Je rappelle mon but : lorsque l'utilisateur modifie la couleur de fond d'une cellule se trouvant sur une feuille de calcul appelée "FD-MDD", il faut que le excel aille tout seul modifier la couleur d'une feuille de calcul correspondant à la cellulle (les noms des cellules sont MDDx) et la couleur de fond d'une cellule sur une AUTRE feuille de calcul appellée "FI".

  12. #12
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut
    Bonjour,

    Donc je passe en worksheet_activate et mon code est :
    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
     
    Private Sub Worksheet_Activate(ByVal Target As Range)
     
    x = ActiveCell.Interior.ColorIndex
     
    Select Case Target.adress
     
    Case Range("B7").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B7:L7").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD1").Tab.ColorIndex = x
     
     
    Case Range("B8").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B8:L8").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD2").Tab.ColorIndex = x
     
     
    Case Range("B9").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B9:L9").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD3").Tab.ColorIndex = x
     
     
    Case Range("B10").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B10:L10").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD4").Tab.ColorIndex = x
     
     
    Case Range("B11").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B11:L11").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD5").Tab.ColorIndex = x
     
     
    Case Range("B12").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B12:L12").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD6").Tab.ColorIndex = x
     
     
    Case Range("B13").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B13:L13").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD7").Tab.ColorIndex = x
     
     
    Case Range("B14").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B14:L14").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD8").Tab.ColorIndex = x
     
     
    Case Range("B15").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B15:L15").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD9").Tab.ColorIndex = x
     
     
    Case Range("B16").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B16:L16").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD10").Tab.ColorIndex = x
     
     
    Case Range("B17").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B17:L17").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD11").Tab.ColorIndex = x
     
     
    Case Range("B18").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B18:L18").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD12").Tab.ColorIndex = x
     
     
    Case Range("B19").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B19:L19").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD13").Tab.ColorIndex = x
     
     
    Case Range("B20").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B20:L20").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD14").Tab.ColorIndex = x
     
     
    Case Range("B21").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B21:L21").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD15").Tab.ColorIndex = x
     
     
    Case Range("B22").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B22:L22").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD16").Tab.ColorIndex = x
     
     
    Case Range("B23").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B23:L23").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD17").Tab.ColorIndex = x
     
     
    Case Range("B24").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B24:L24").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD18").Tab.ColorIndex = x
     
     
    Case Range("B25").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B25:L25").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD19").Tab.ColorIndex = x
     
     
    Case Range("B26").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B26:L26").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD20").Tab.ColorIndex = x
     
     
    Case Range("B29").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B27:L27").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD21").Tab.ColorIndex = x
     
     
    Case Range("B30").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B28:L28").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD22").Tab.ColorIndex = x
     
     
    Case Range("B31").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B29:L29").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD23").Tab.ColorIndex = x
     
     
    Case Range("B32").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B30:L30").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD24").Tab.ColorIndex = x
     
     
    Case Range("B33").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B31:L31").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD25").Tab.ColorIndex = x
     
     
    Case Range("B34").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B32:L32").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD26").Tab.ColorIndex = x
     
     
    Case Range("B35").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B33:L33").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD27").Tab.ColorIndex = x
     
     
    Case Range("B36").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B34:L34").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD28").Tab.ColorIndex = x
     
     
    Case Range("B37").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B35:L35").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD29").Tab.ColorIndex = x
     
     
    Case Range("B38").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B36:L36").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD30").Tab.ColorIndex = x
     
     
    Case Range("B39").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B37:L37").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD31").Tab.ColorIndex = x
     
     
    Case Range("B42").adress
    If x = 16 Then Thisworbook.Sheets("FI").Range("B38:L38").Interior.ColorIndex = x
                    ActiveWorkbook.Sheets("MDD32").Tab.ColorIndex = x
     
    End Select
    End Sub
    Hélas ce code me donne une erreur de compilation :
    La déclaration de la procédure ne correspond pas à la description de l'événement ou de la procédure de même nom.
    Je ne vois pas comment corriger cette erreur ...

    Sinon pour la macro de mise à jour, ça donnerait ça :
    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
     
        Sub MAJ()
        Sheets("MDD1").Select
        Sheets("MDD2").Select
        Sheets("MDD3").Select
        Sheets("MDD4").Select
        Sheets("MDD5").Select
        Sheets("MDD6").Select
        Sheets("MDD7").Select
        Sheets("MDD8").Select
        Sheets("MDD9").Select
        Sheets("MDD10").Select
        Sheets("MDD11").Select
        Sheets("MDD12").Select
        Sheets("MDD13").Select
        Sheets("MDD14").Select
        Sheets("MDD15").Select
        Sheets("MDD16").Select
        Sheets("MDD17").Select
        Sheets("MDD18").Select
        Sheets("MDD19").Select
        Sheets("MDD20").Select
        Sheets("MDD21").Select
        Sheets("MDD22").Select
        Sheets("MDD23").Select
        Sheets("MDD24").Select
        Sheets("MDD25").Select
        Sheets("MDD26").Select
        Sheets("MDD27").Select
        Sheets("MDD28").Select
        Sheets("MDD29").Select
        Sheets("MDD30").Select
        Sheets("MDD31").Select
        Sheets("MDD32").Select
        Sheets("FI").Select
        ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
        Sheets("FD-MDD").Select
    End Sub
    Merci,
    Kulnae.

  13. #13
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    Le bon code serai :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
     
    dim x as integer
     
    x= worksheets("FD-MDD").Range("la case qui corespond à la feuille").interior.colorindex
    Sh.tab.colorindex = x
     
    End Sub
    Sinon si tu fait un bouton de mise à jour, pas besoin de passer par sheet activate, tu parcours les cellule de la feuille ("FD-MDD") et tu met à jour la couleur de tous les onglets:

    Si tu peux envoyer ton fichier je purrai peut être etre plus précis.

  14. #14
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut
    Je ne vois pas très bien ce que fais ton code ... Pourrais tu m'expliquer "Sh.tab.colorindex = x" ?

    Sinon pour le fichier, si je pouvais éviter de te l'envoyer, ce serait mieux ... C'est un document confidentiel de l'entreprise dans laquelle je travaille en tant que stagiaire ... il faudrait que je fasse une demande qui se terminerait certainement par un refus ...

  15. #15
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Private Sub Workbook_SheetActivate(ByVal Sh As Object)
     
    dim x as integer
     
    x= worksheets("FD-MDD").Range("la case qui corespond à la feuille").interior.colorindex
    Sh.tab.colorindex = x
     
    End Sub
    Ici le Private Sub Workbook_SheetActivate(ByVal Sh As Object) permet de lancer la macro quand tu active la feuille, le byval, sh as object veut dire que Sh est la feuille que tu viens d'activer.

    Donc le Sh.tab.colorindex=x

    permet de colorier l'onglet(tab) de la feuille que tu viens d'activer(Sh) avec le colorindex x (celui dela case que tu as mis ici: x= worksheets("FD-MDD").Range("la case qui corespond à la feuille").interior.colorindex

  16. #16
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut
    Donc le Sh.tab.colorindex=x

    permet de colorier l'onglet(tab) de la feuille que tu viens d'activer(Sh) avec le colorindex x (celui dela case que tu as mis ici: x= worksheets("FD-MDD").Range("la case qui corespond à la feuille").interior.colorindex
    Mais le problème est que le Sh ne varie pas non ? Sh reste "FD-MDD" et je ne veux pas changer la couleur de la feuille "FD-MDD"

    Donc pour l'instant le code est :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    Private Sub Worksheet_Activate(ByVal Sh As Object)
     
    Dim x As Integer
     
    Case Range("B7").adress
    x = Worksheet("FD-MDD").Range("B7").Interior.ColorIndex
    Thisworkbook.Sheets("FI").Range("B7:L7").Interior.ColorIndex = x
    ActiveWorkbook.Sheets("MDD1").Tab.ColorIndex = x
    Donc comment faire pour que Sh passe de FD-MDD en MDDy (1 <= y <= 32) ?
    (pour rapprocher le code à celui que tu viens de me donner)
    Puisqu'en fait j'ai toujours la même erreur de compilation qu'au dessus ...

    Aussi :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Thisworkbook.Sheets("FI").Range("B7:L7").Interior.ColorIndex = x
    Cette partie du code aura-t'elle pour effet de colorier en ColorIndex x la couleur de fond des cases B7 à L7 de la feuille FI ? (Le code est il donc correct ?)

    Merci,
    Kulnae.

  17. #17
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    Oui cette partie permet de colorier en ColorIndex x la couleur de fond des cases B7 à L7 de la feuille FI
    Thisworkbook.Sheets("FI").Range("B7:L7").Interior.ColorIndex = x
    Mais il faut plutôt ecrire
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Thisworkbook.Sheets("FI").Range("B7","L7").Interior.ColorIndex = x
    J'avais déjà corrigé cette erreur:

    La syntaxe est

    ou equivalent si tu veux utiliser les numeros de ligne et de colonne:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    range(cells(1,1),cells(1,10))
    Visiblement t'es un peu perdu:

    Donc pour l'instant le code est :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Private Sub Worksheet_Activate(ByVal Sh As Object)
     
    Dim x As Integer
     
    Case Range("B7").adress
    x = Worksheet("FD-MDD").Range("B7").Interior.ColorIndex
    Thisworkbook.Sheets("FI").Range("B7:L7").Interior.ColorIndex = x
    ActiveWorkbook.Sheets("MDD1").Tab.ColorIndex = x
    Ici le case ne sert a rien. Pour utiliser case, il faut d'abord mettre la ligne

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Select Case = target.adress 'par exemple, mais on peut regarder autre chose que l'adresse de la cible(target)
    Sachant qu'il faut au préalable definir ce qu'est target:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Dim target as range
     
    target= range("B1")
    Dans le cas ou on se place dans:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    End Sub
    target est défini comme range et target sera automatiquement défini comme la case ayant changé donc pas besoin de target = range("quelque chose")

  18. #18
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut
    J'avais oublié de recopier le select ... (il est bien présent dans mon code)
    Sinon je vois le fonctionnement, ça ressemble à un switch en c++.

    Mais là avec le code suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
     
     
    Private Sub Worksheet_Activate(ByVal Sh As Object)
     
    Dim x As Integer
    Dim Target As Range
     
    Select Case Target.adress
     
    Case Range("B7").adress
     
    x = Worksheet("FD-MDD").Range("B7").Interior.ColorIndex
    Thisworkbook.Sheets("FI").Range("B7","L7").Interior.ColorIndex  = x
    ActiveWorkbook.Sheets("MDD1").Tab.ColorIndex = x
    J'obtiens une erreur de compilation :

    La déclaration de la procédure ne correspond pas à la description de l'événement ou de la procédure de même nom.
    Mais donc où utilise t'on l'objet Sh ? Le problème vient de là non ?

    Aussi :
    Sinon si tu fait un bouton de mise à jour, pas besoin de passer par sheet activate, tu parcours les cellule de la feuille ("FD-MDD") et tu met à jour la couleur de tous les onglets
    Comment réaliser cela ? Je pense que je vais finir par t'envoyer le fichier depuis chez moi ...

    Merci,
    Kulnae.

  19. #19
    Membre actif
    Inscrit en
    Août 2009
    Messages
    284
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Août 2009
    Messages : 284
    Points : 283
    Points
    283
    Par défaut
    Je pense que pour le bouton ça devrait le faire:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    Private Sub CommandButton1_Click()
     
    Dim nom As String
     
    For i = 7 To 19
    If Cells(2, i).ColorIndex = 16 Then
    Thisworbook.Sheets("FI").Range(Cells(2, i), Cells(12, i)).Interior.ColorIndex = 16
    nom = "MDD" & i - 6
    ThisWorkbook.Sheets(nom).Tab.ColorIndex = 16
    End If
    Next i
     
    End Sub
    Ajoute un bouton dans ta feuille FD-MDD et tu met ça dans le code de la feuille FD-MDD

    Clic sur le bouton et voit si ça va

  20. #20
    Futur Membre du Club
    Profil pro
    Inscrit en
    Août 2009
    Messages
    22
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2009
    Messages : 22
    Points : 6
    Points
    6
    Par défaut
    Et pour le code même de la feuille et de ce que le bouton est censé mettre à jour, j'obtiens toujours une erreur de compilation ...

    Comment la corriger ?

    Merci,
    Kulnae.

Discussions similaires

  1. Réponses: 3
    Dernier message: 14/08/2012, 10h24
  2. Réponses: 0
    Dernier message: 22/02/2012, 17h23
  3. [XL-2003] Remplissage d'une cellule en fonction du contenu d'autres cellules.
    Par homer83140 dans le forum Excel
    Réponses: 27
    Dernier message: 13/01/2011, 16h39
  4. [XL-97] Changement valeur d'une cellule en fonction de valeurs d'autres cellules
    Par chubak62 dans le forum Macros et VBA Excel
    Réponses: 5
    Dernier message: 09/01/2011, 10h21
  5. Sommer des cellules en fonction du contenu d'autres cellules
    Par jnmab dans le forum Macros et VBA Excel
    Réponses: 11
    Dernier message: 30/12/2007, 22h05

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