Bonjour à vous tous.
Lors d'un précédent message, MichDenis m'avait donné ce code. Il fonctionne parfaitement. Le problème que j'ai, c'est que mon
fichier, (exemple la colonne C) ce sont des cellules qui font des calculs. Cette macro change la couleur lorsque je fais ma somme la
première fois, mais ne change pas si je vais changer les chiffres de la colonne A ou B. Voici un exemple:
Cellule A2= 2
Cellule B2= 11
Cellule C2= = A2+B2= 12, donc la couleur devrait être rouge. Jusqu'à là, ça fonctionne. Mais si je retourne dans la cellule B2
et que je change le chiffre 11 pour 0, la couleur devrait être vert, mais elle ne change pas.
Est-ce que quelqu'un peut m'aider?.
En espérant avoir été claire. Merci de votre aide.
Je joins un fichier Exemple et le code utilisé.
http://cjoint.com/?fmv6NhOAEL
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Rg As Range
Set Rg = Intersect(Target, Union(Range("c2:c23"), Range("d2:d23")))
If Not Rg Is Nothing Then
For Each c In Rg
With c
Select Case Target.Value
Case Is >= 12
.Interior.ColorIndex = 3
Case Is >=7
.Interior.ColorIndex = 46
Case Is >= 5
.Interior.ColorIndex = 6
Case Is >= 0
.Interior.ColorIndex = 10
End Select
End With
Next
End If
End Sub
Cette action est irreversible, confirmez la suppression du commentaire ?
Signaler le commentaire
Veuillez sélectionner un problème
Nudité
Violence
Harcèlement
Fraude
Vente illégale
Discours haineux
Terrorisme
Autre
marc
Bonsoir, Oubliez mon premier message. Je pensais être capable de modifer mon code, mais cela ne fonctionne pas. Voici un autre fichier qui monte le vrai problème. http://cjoint.com/?fnetTMUc52
J'ai la colonne D et la colonne G qui sont des colonnes de couleur. Les 2 suivent le même code de couleur. La colonne D est la multiplication de la colonne B et C. La colonne G, est le résultat de la colonne D et la colonne F. Mon code ne fonctionne uniquement que pour la première colonne (la colonne D) Voici mon code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim Rg As Range Dim formulaCell As Range Set Rg = Intersect(Target, Union(Cells(1, "b").EntireColumn, Cells(1, "c").EntireColumn)) If Not Rg Is Nothing Then For Each c In Rg Set formulaCell = Cells(c.Row, "d") Select Case formulaCell.Value Case Is >= 12 formulaCell.Interior.ColorIndex = 3 Case Is >= 7 formulaCell.Interior.ColorIndex = 46 Case Is >= 5 formulaCell.Interior.ColorIndex = 6 Case Is >= 0 formulaCell.Interior.ColorIndex = 10 End Select Next End If End Sub
Merci de m'aider à modifier ce code pour ma réalité. Marc
"marc" a écrit dans le message de news:
Bonjour à vous tous. Lors d'un précédent message, MichDenis m'avait donné ce code. Il fonctionne parfaitement. Le problème que j'ai, c'est que mon fichier, (exemple la colonne C) ce sont des cellules qui font des calculs. Cette macro change la couleur lorsque je fais ma somme la première fois, mais ne change pas si je vais changer les chiffres de la colonne A ou B. Voici un exemple:
Cellule A2= 2 Cellule B2= 11 Cellule C2= = A2+B2= 12, donc la couleur devrait être rouge. Jusqu'à là, ça fonctionne. Mais si je retourne dans la cellule B2 et que je change le chiffre 11 pour 0, la couleur devrait être vert, mais elle ne change pas. Est-ce que quelqu'un peut m'aider?. En espérant avoir été claire. Merci de votre aide. Je joins un fichier Exemple et le code utilisé.
http://cjoint.com/?fmv6NhOAEL
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim Rg As Range Set Rg = Intersect(Target, Union(Range("c2:c23"), Range("d2:d23"))) If Not Rg Is Nothing Then For Each c In Rg With c Select Case Target.Value Case Is >= 12 .Interior.ColorIndex = 3 Case Is >=7 .Interior.ColorIndex = 46 Case Is >= 5 .Interior.ColorIndex = 6 Case Is >= 0 .Interior.ColorIndex = 10 End Select End With Next End If End Sub
Bonsoir,
Oubliez mon premier message.
Je pensais être capable de modifer mon code, mais cela ne fonctionne pas.
Voici un autre fichier qui monte le vrai problème.
http://cjoint.com/?fnetTMUc52
J'ai la colonne D et la colonne G qui sont des colonnes de couleur.
Les 2 suivent le même code de couleur.
La colonne D est la multiplication de la colonne B et C.
La colonne G, est le résultat de la colonne D et la colonne F.
Mon code ne fonctionne uniquement que pour la première colonne (la colonne
D)
Voici mon code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Rg As Range
Dim formulaCell As Range
Set Rg = Intersect(Target, Union(Cells(1, "b").EntireColumn, Cells(1,
"c").EntireColumn))
If Not Rg Is Nothing Then
For Each c In Rg
Set formulaCell = Cells(c.Row, "d")
Select Case formulaCell.Value
Case Is >= 12
formulaCell.Interior.ColorIndex = 3
Case Is >= 7
formulaCell.Interior.ColorIndex = 46
Case Is >= 5
formulaCell.Interior.ColorIndex = 6
Case Is >= 0
formulaCell.Interior.ColorIndex = 10
End Select
Next
End If
End Sub
Merci de m'aider à modifier ce code pour ma réalité.
Marc
"marc" <test@test.com> a écrit dans le message de
news:umBwaxz0JHA.3408@TK2MSFTNGP04.phx.gbl...
Bonjour à vous tous.
Lors d'un précédent message, MichDenis m'avait donné ce code. Il
fonctionne parfaitement. Le problème que j'ai, c'est que mon fichier,
(exemple la colonne C) ce sont des cellules qui font des calculs. Cette
macro change la couleur lorsque je fais ma somme la première fois, mais ne
change pas si je vais changer les chiffres de la colonne A ou B. Voici un
exemple:
Cellule A2= 2
Cellule B2= 11
Cellule C2= = A2+B2= 12, donc la couleur devrait être rouge. Jusqu'à
là, ça fonctionne. Mais si je retourne dans la cellule B2 et que je change
le chiffre 11 pour 0, la couleur devrait être vert, mais elle ne change
pas.
Est-ce que quelqu'un peut m'aider?.
En espérant avoir été claire. Merci de votre aide.
Je joins un fichier Exemple et le code utilisé.
http://cjoint.com/?fmv6NhOAEL
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim Rg As Range
Set Rg = Intersect(Target, Union(Range("c2:c23"), Range("d2:d23")))
If Not Rg Is Nothing Then
For Each c In Rg
With c
Select Case Target.Value
Case Is >= 12
.Interior.ColorIndex = 3
Case Is >=7
.Interior.ColorIndex = 46
Case Is >= 5
.Interior.ColorIndex = 6
Case Is >= 0
.Interior.ColorIndex = 10
End Select
End With
Next
End If
End Sub
Bonsoir, Oubliez mon premier message. Je pensais être capable de modifer mon code, mais cela ne fonctionne pas. Voici un autre fichier qui monte le vrai problème. http://cjoint.com/?fnetTMUc52
J'ai la colonne D et la colonne G qui sont des colonnes de couleur. Les 2 suivent le même code de couleur. La colonne D est la multiplication de la colonne B et C. La colonne G, est le résultat de la colonne D et la colonne F. Mon code ne fonctionne uniquement que pour la première colonne (la colonne D) Voici mon code:
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim Rg As Range Dim formulaCell As Range Set Rg = Intersect(Target, Union(Cells(1, "b").EntireColumn, Cells(1, "c").EntireColumn)) If Not Rg Is Nothing Then For Each c In Rg Set formulaCell = Cells(c.Row, "d") Select Case formulaCell.Value Case Is >= 12 formulaCell.Interior.ColorIndex = 3 Case Is >= 7 formulaCell.Interior.ColorIndex = 46 Case Is >= 5 formulaCell.Interior.ColorIndex = 6 Case Is >= 0 formulaCell.Interior.ColorIndex = 10 End Select Next End If End Sub
Merci de m'aider à modifier ce code pour ma réalité. Marc
"marc" a écrit dans le message de news:
Bonjour à vous tous. Lors d'un précédent message, MichDenis m'avait donné ce code. Il fonctionne parfaitement. Le problème que j'ai, c'est que mon fichier, (exemple la colonne C) ce sont des cellules qui font des calculs. Cette macro change la couleur lorsque je fais ma somme la première fois, mais ne change pas si je vais changer les chiffres de la colonne A ou B. Voici un exemple:
Cellule A2= 2 Cellule B2= 11 Cellule C2= = A2+B2= 12, donc la couleur devrait être rouge. Jusqu'à là, ça fonctionne. Mais si je retourne dans la cellule B2 et que je change le chiffre 11 pour 0, la couleur devrait être vert, mais elle ne change pas. Est-ce que quelqu'un peut m'aider?. En espérant avoir été claire. Merci de votre aide. Je joins un fichier Exemple et le code utilisé.
http://cjoint.com/?fmv6NhOAEL
Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim Rg As Range Set Rg = Intersect(Target, Union(Range("c2:c23"), Range("d2:d23"))) If Not Rg Is Nothing Then For Each c In Rg With c Select Case Target.Value Case Is >= 12 .Interior.ColorIndex = 3 Case Is >=7 .Interior.ColorIndex = 46 Case Is >= 5 .Interior.ColorIndex = 6 Case Is >= 0 .Interior.ColorIndex = 10 End Select End With Next End If End Sub
Francois L
marc a écrit :
Bonjour,
Ca ? '----------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim col As Integer, Cel1 As Range, cel2 As Range col = Target.Column If col < 2 Or col > 3 Then Exit Sub Set Cel1 = Cells(Target.Row, "D") Set cel2 = Cells(Target.Row, "G") Select Case Cel1.Value Case Is >= 12 Cel1.Interior.ColorIndex = 3 Case Is >= 7 Cel1.Interior.ColorIndex = 46 Case Is >= 5 Cel1.Interior.ColorIndex = 6 Case Is >= 0 Cel1.Interior.ColorIndex = 10 Case Else Cel1.Interior.ColorIndex = xlNone End Select Select Case cel2.Value Case Is >= 12 cel2.Interior.ColorIndex = 3 Case Is >= 7 cel2.Interior.ColorIndex = 46 Case Is >= 5 cel2.Interior.ColorIndex = 6 Case Is >= 0 cel2.Interior.ColorIndex = 10 Case Else cel2.Interior.ColorIndex = xlNone End Select
End Sub '----------------------------------------------- -- François L
marc a écrit :
Bonjour,
Ca ?
'-----------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim col As Integer, Cel1 As Range, cel2 As Range
col = Target.Column
If col < 2 Or col > 3 Then Exit Sub
Set Cel1 = Cells(Target.Row, "D")
Set cel2 = Cells(Target.Row, "G")
Select Case Cel1.Value
Case Is >= 12
Cel1.Interior.ColorIndex = 3
Case Is >= 7
Cel1.Interior.ColorIndex = 46
Case Is >= 5
Cel1.Interior.ColorIndex = 6
Case Is >= 0
Cel1.Interior.ColorIndex = 10
Case Else
Cel1.Interior.ColorIndex = xlNone
End Select
Select Case cel2.Value
Case Is >= 12
cel2.Interior.ColorIndex = 3
Case Is >= 7
cel2.Interior.ColorIndex = 46
Case Is >= 5
cel2.Interior.ColorIndex = 6
Case Is >= 0
cel2.Interior.ColorIndex = 10
Case Else
cel2.Interior.ColorIndex = xlNone
End Select
End Sub
'-----------------------------------------------
--
François L
Ca ? '----------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim col As Integer, Cel1 As Range, cel2 As Range col = Target.Column If col < 2 Or col > 3 Then Exit Sub Set Cel1 = Cells(Target.Row, "D") Set cel2 = Cells(Target.Row, "G") Select Case Cel1.Value Case Is >= 12 Cel1.Interior.ColorIndex = 3 Case Is >= 7 Cel1.Interior.ColorIndex = 46 Case Is >= 5 Cel1.Interior.ColorIndex = 6 Case Is >= 0 Cel1.Interior.ColorIndex = 10 Case Else Cel1.Interior.ColorIndex = xlNone End Select Select Case cel2.Value Case Is >= 12 cel2.Interior.ColorIndex = 3 Case Is >= 7 cel2.Interior.ColorIndex = 46 Case Is >= 5 cel2.Interior.ColorIndex = 6 Case Is >= 0 cel2.Interior.ColorIndex = 10 Case Else cel2.Interior.ColorIndex = xlNone End Select
End Sub '----------------------------------------------- -- François L
marc
Bonjour Franois L Ça fonctionne parfaitement, merci de ton aide et bonne journée Marc
"Francois L" a écrit dans le message de news:%
marc a écrit :
Bonjour,
Ca ? '----------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim col As Integer, Cel1 As Range, cel2 As Range col = Target.Column If col < 2 Or col > 3 Then Exit Sub Set Cel1 = Cells(Target.Row, "D") Set cel2 = Cells(Target.Row, "G") Select Case Cel1.Value Case Is >= 12 Cel1.Interior.ColorIndex = 3 Case Is >= 7 Cel1.Interior.ColorIndex = 46 Case Is >= 5 Cel1.Interior.ColorIndex = 6 Case Is >= 0 Cel1.Interior.ColorIndex = 10 Case Else Cel1.Interior.ColorIndex = xlNone End Select Select Case cel2.Value Case Is >= 12 cel2.Interior.ColorIndex = 3 Case Is >= 7 cel2.Interior.ColorIndex = 46 Case Is >= 5 cel2.Interior.ColorIndex = 6 Case Is >= 0 cel2.Interior.ColorIndex = 10 Case Else cel2.Interior.ColorIndex = xlNone End Select
End Sub '----------------------------------------------- -- François L
Bonjour Franois L
Ça fonctionne parfaitement, merci de ton aide et bonne journée
Marc
"Francois L" <gardiendephare@etbalises.fr.invalid> a écrit dans le message
de news:%23e7w0R40JHA.4756@TK2MSFTNGP05.phx.gbl...
marc a écrit :
Bonjour,
Ca ?
'-----------------------------------------------------
Private Sub Worksheet_Change(ByVal Target As Excel.Range)
Dim col As Integer, Cel1 As Range, cel2 As Range
col = Target.Column
If col < 2 Or col > 3 Then Exit Sub
Set Cel1 = Cells(Target.Row, "D")
Set cel2 = Cells(Target.Row, "G")
Select Case Cel1.Value
Case Is >= 12
Cel1.Interior.ColorIndex = 3
Case Is >= 7
Cel1.Interior.ColorIndex = 46
Case Is >= 5
Cel1.Interior.ColorIndex = 6
Case Is >= 0
Cel1.Interior.ColorIndex = 10
Case Else
Cel1.Interior.ColorIndex = xlNone
End Select
Select Case cel2.Value
Case Is >= 12
cel2.Interior.ColorIndex = 3
Case Is >= 7
cel2.Interior.ColorIndex = 46
Case Is >= 5
cel2.Interior.ColorIndex = 6
Case Is >= 0
cel2.Interior.ColorIndex = 10
Case Else
cel2.Interior.ColorIndex = xlNone
End Select
End Sub
'-----------------------------------------------
--
François L
Bonjour Franois L Ça fonctionne parfaitement, merci de ton aide et bonne journée Marc
"Francois L" a écrit dans le message de news:%
marc a écrit :
Bonjour,
Ca ? '----------------------------------------------------- Private Sub Worksheet_Change(ByVal Target As Excel.Range) Dim col As Integer, Cel1 As Range, cel2 As Range col = Target.Column If col < 2 Or col > 3 Then Exit Sub Set Cel1 = Cells(Target.Row, "D") Set cel2 = Cells(Target.Row, "G") Select Case Cel1.Value Case Is >= 12 Cel1.Interior.ColorIndex = 3 Case Is >= 7 Cel1.Interior.ColorIndex = 46 Case Is >= 5 Cel1.Interior.ColorIndex = 6 Case Is >= 0 Cel1.Interior.ColorIndex = 10 Case Else Cel1.Interior.ColorIndex = xlNone End Select Select Case cel2.Value Case Is >= 12 cel2.Interior.ColorIndex = 3 Case Is >= 7 cel2.Interior.ColorIndex = 46 Case Is >= 5 cel2.Interior.ColorIndex = 6 Case Is >= 0 cel2.Interior.ColorIndex = 10 Case Else cel2.Interior.ColorIndex = xlNone End Select
End Sub '----------------------------------------------- -- François L