Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

plusieurs conditions

4 réponses
Avatar
Congelator
Salut tout le monde,
j'ai besoin de ch'ti coup de main pour adapter ce code que j'ai trouvé dans
le forum (merci à son concepteur...). Les conditions sont les suivantes :
dans la cellule G3, un chifre de -4 à >1. Dans H3, un autre chiffre en
fonction de G3 et ainsi de suite jusqu'à G1000. Exprimé autrement, ça
donnerait quelque chose comme ça :
si G3:G1000 >1; H3:H1000=0
si G3:G1000 = 1; H3:H1000= 1
si G3:G1000 = 0; H3:H1000= 2
si G3:G1000 = -1; H3:H1000= 3
si G3:G1000 = -2; H3:H1000= 4
si G3:G1000 = -3; H3:H1000= 5
si G3:G1000 = -4; H3:H1000= 6

Comment l'adapter à ce code-là ??? Ou, si ce n'est pas possible, comment
faire ??

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Not Intersect(Target.Cells, Range("A1:A10")) Is Nothing Then
For Each c In Target
Select Case c.Value
Case "1": c.Font.ColorIndex = 3: c.Interior.ColorIndex = 1
Case "2": c.Font.ColorIndex = 2: c.Interior.ColorIndex = 2
Case "3": c.Font.ColorIndex = 4: c.Interior.ColorIndex = 3
Case "4": c.Font.ColorIndex = 23: c.Interior.ColorIndex = 4
Case "5": c.Font.ColorIndex = 13: c.Interior.ColorIndex = 5
Case "6": c.Font.ColorIndex = 9: c.Interior.ColorIndex = 6
Case Else: c.Font.ColorIndex = xlAutomatic:
c.Interior.ColorIndex = xlNone
End Select
Next
End If
End Sub

Merci d'avance !

PS : je vais également le mettre dans le forum VBA... Il sera peut-être plus
approprié.
--
Céd / Lausanne

4 réponses

Avatar
Elliac
Bonjour,

der = Range("g50000").End(xlUp).Row
Range("h3:h" & der) = _
"=IF(RC[-1]>1,0,IF(RC[-1]<-4,"""",IF(RC[-1]<=0,ABS(RC[-1])+2,1)))"

Camille

"Congelator" wrote:

Salut tout le monde,
j'ai besoin de ch'ti coup de main pour adapter ce code que j'ai trouvé dans
le forum (merci à son concepteur...). Les conditions sont les suivantes :
dans la cellule G3, un chifre de -4 à >1. Dans H3, un autre chiffre en
fonction de G3 et ainsi de suite jusqu'à G1000. Exprimé autrement, ça
donnerait quelque chose comme ça :
si G3:G1000 >1; H3:H1000=0
si G3:G1000 = 1; H3:H1000= 1
si G3:G1000 = 0; H3:H1000= 2
si G3:G1000 = -1; H3:H1000= 3
si G3:G1000 = -2; H3:H1000= 4
si G3:G1000 = -3; H3:H1000= 5
si G3:G1000 = -4; H3:H1000= 6

Comment l'adapter à ce code-là ??? Ou, si ce n'est pas possible, comment
faire ??

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Not Intersect(Target.Cells, Range("A1:A10")) Is Nothing Then
For Each c In Target
Select Case c.Value
Case "1": c.Font.ColorIndex = 3: c.Interior.ColorIndex = 1
Case "2": c.Font.ColorIndex = 2: c.Interior.ColorIndex = 2
Case "3": c.Font.ColorIndex = 4: c.Interior.ColorIndex = 3
Case "4": c.Font.ColorIndex = 23: c.Interior.ColorIndex = 4
Case "5": c.Font.ColorIndex = 13: c.Interior.ColorIndex = 5
Case "6": c.Font.ColorIndex = 9: c.Interior.ColorIndex = 6
Case Else: c.Font.ColorIndex = xlAutomatic:
c.Interior.ColorIndex = xlNone
End Select
Next
End If
End Sub

Merci d'avance !

PS : je vais également le mettre dans le forum VBA... Il sera peut-être plus
approprié.
--
Céd / Lausanne


Avatar
Congelator
Salut Camille,

Merci pour le coup de main mais ça ne fonctionne pas, en tout cas chez moi.
Je pense que cela vient du code dans lequel j'ai inséré tes lignes.

Voilà comment je l'ai inséré.. où est l'erreur ?

Private Sub Worksheet_Change(ByVal Target As Range)
der = Range("g50000").End(xlUp).Row
Range("h3:h" & der) = _
"=IF(RC[-1]>1,0,IF(RC[-1]<-4,"""",IF(RC[-1]<=0,ABS(RC[-1])+2,1)))"
End Sub

merci de ton aide
--
Céd / Lausanne



Bonjour,

der = Range("g50000").End(xlUp).Row
Range("h3:h" & der) = _
"=IF(RC[-1]>1,0,IF(RC[-1]<-4,"""",IF(RC[-1]<=0,ABS(RC[-1])+2,1)))"

Camille

"Congelator" wrote:

Salut tout le monde,
j'ai besoin de ch'ti coup de main pour adapter ce code que j'ai trouvé dans
le forum (merci à son concepteur...). Les conditions sont les suivantes :
dans la cellule G3, un chifre de -4 à >1. Dans H3, un autre chiffre en
fonction de G3 et ainsi de suite jusqu'à G1000. Exprimé autrement, ça
donnerait quelque chose comme ça :
si G3:G1000 >1; H3:H1000=0
si G3:G1000 = 1; H3:H1000= 1
si G3:G1000 = 0; H3:H1000= 2
si G3:G1000 = -1; H3:H1000= 3
si G3:G1000 = -2; H3:H1000= 4
si G3:G1000 = -3; H3:H1000= 5
si G3:G1000 = -4; H3:H1000= 6

Comment l'adapter à ce code-là ??? Ou, si ce n'est pas possible, comment
faire ??

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Not Intersect(Target.Cells, Range("A1:A10")) Is Nothing Then
For Each c In Target
Select Case c.Value
Case "1": c.Font.ColorIndex = 3: c.Interior.ColorIndex = 1
Case "2": c.Font.ColorIndex = 2: c.Interior.ColorIndex = 2
Case "3": c.Font.ColorIndex = 4: c.Interior.ColorIndex = 3
Case "4": c.Font.ColorIndex = 23: c.Interior.ColorIndex = 4
Case "5": c.Font.ColorIndex = 13: c.Interior.ColorIndex = 5
Case "6": c.Font.ColorIndex = 9: c.Interior.ColorIndex = 6
Case Else: c.Font.ColorIndex = xlAutomatic:
c.Interior.ColorIndex = xlNone
End Select
Next
End If
End Sub

Merci d'avance !

PS : je vais également le mettre dans le forum VBA... Il sera peut-être plus
approprié.
--
Céd / Lausanne




Avatar
Congelator
Salut Camille,

JT m'a founi LA solution... alors la voici pour ceux que ça intéressesait.
Merci quand même pour ton aide.

B1 = Km déjà parcourus (deja)
B2 = Km du mois (km)
B3 = total b1+b2

B4 = -8000 : =MAX(0;MIN(8000-deja;km))
B5 = 8 - 15000 : =MAX(0;MIN(15000-deja;km))-B4
B6 = + 15000 : =km-B5-B4


--
Céd / Lausanne



Bonjour,

der = Range("g50000").End(xlUp).Row
Range("h3:h" & der) = _
"=IF(RC[-1]>1,0,IF(RC[-1]<-4,"""",IF(RC[-1]<=0,ABS(RC[-1])+2,1)))"

Camille

"Congelator" wrote:

Salut tout le monde,
j'ai besoin de ch'ti coup de main pour adapter ce code que j'ai trouvé dans
le forum (merci à son concepteur...). Les conditions sont les suivantes :
dans la cellule G3, un chifre de -4 à >1. Dans H3, un autre chiffre en
fonction de G3 et ainsi de suite jusqu'à G1000. Exprimé autrement, ça
donnerait quelque chose comme ça :
si G3:G1000 >1; H3:H1000=0
si G3:G1000 = 1; H3:H1000= 1
si G3:G1000 = 0; H3:H1000= 2
si G3:G1000 = -1; H3:H1000= 3
si G3:G1000 = -2; H3:H1000= 4
si G3:G1000 = -3; H3:H1000= 5
si G3:G1000 = -4; H3:H1000= 6

Comment l'adapter à ce code-là ??? Ou, si ce n'est pas possible, comment
faire ??

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Not Intersect(Target.Cells, Range("A1:A10")) Is Nothing Then
For Each c In Target
Select Case c.Value
Case "1": c.Font.ColorIndex = 3: c.Interior.ColorIndex = 1
Case "2": c.Font.ColorIndex = 2: c.Interior.ColorIndex = 2
Case "3": c.Font.ColorIndex = 4: c.Interior.ColorIndex = 3
Case "4": c.Font.ColorIndex = 23: c.Interior.ColorIndex = 4
Case "5": c.Font.ColorIndex = 13: c.Interior.ColorIndex = 5
Case "6": c.Font.ColorIndex = 9: c.Interior.ColorIndex = 6
Case Else: c.Font.ColorIndex = xlAutomatic:
c.Interior.ColorIndex = xlNone
End Select
Next
End If
End Sub

Merci d'avance !

PS : je vais également le mettre dans le forum VBA... Il sera peut-être plus
approprié.
--
Céd / Lausanne




Avatar
Congelator
Salut Camille,

J'ai trouvé la solution. C'était tout simple mais je croyais qu'on était
limité à 6 conditions mais c'est 7... alors tout baigne. Pour info, voila
comment j'ai remédié à ça.

=SI(G4>1;0;SI(G4=1;1;SI(G4=0;2;SI(G4=-1;3;SI(G4=-2;4;SI(G4=-3;5;SI(G4=-4;6;"")))))))

Merci quand même pour ta solution.

--
Céd / Lausanne



Bonjour,

der = Range("g50000").End(xlUp).Row
Range("h3:h" & der) = _
"=IF(RC[-1]>1,0,IF(RC[-1]<-4,"""",IF(RC[-1]<=0,ABS(RC[-1])+2,1)))"

Camille

"Congelator" wrote:

Salut tout le monde,
j'ai besoin de ch'ti coup de main pour adapter ce code que j'ai trouvé dans
le forum (merci à son concepteur...). Les conditions sont les suivantes :
dans la cellule G3, un chifre de -4 à >1. Dans H3, un autre chiffre en
fonction de G3 et ainsi de suite jusqu'à G1000. Exprimé autrement, ça
donnerait quelque chose comme ça :
si G3:G1000 >1; H3:H1000=0
si G3:G1000 = 1; H3:H1000= 1
si G3:G1000 = 0; H3:H1000= 2
si G3:G1000 = -1; H3:H1000= 3
si G3:G1000 = -2; H3:H1000= 4
si G3:G1000 = -3; H3:H1000= 5
si G3:G1000 = -4; H3:H1000= 6

Comment l'adapter à ce code-là ??? Ou, si ce n'est pas possible, comment
faire ??

Private Sub Worksheet_Change(ByVal Target As Range)
Dim c As Range
If Not Intersect(Target.Cells, Range("A1:A10")) Is Nothing Then
For Each c In Target
Select Case c.Value
Case "1": c.Font.ColorIndex = 3: c.Interior.ColorIndex = 1
Case "2": c.Font.ColorIndex = 2: c.Interior.ColorIndex = 2
Case "3": c.Font.ColorIndex = 4: c.Interior.ColorIndex = 3
Case "4": c.Font.ColorIndex = 23: c.Interior.ColorIndex = 4
Case "5": c.Font.ColorIndex = 13: c.Interior.ColorIndex = 5
Case "6": c.Font.ColorIndex = 9: c.Interior.ColorIndex = 6
Case Else: c.Font.ColorIndex = xlAutomatic:
c.Interior.ColorIndex = xlNone
End Select
Next
End If
End Sub

Merci d'avance !

PS : je vais également le mettre dans le forum VBA... Il sera peut-être plus
approprié.
--
Céd / Lausanne