2 réponses
Bonjour,
Le raisonnement est bon mais pas la syntaxe
NB: Le cas ou les cellules sont égales n'est pas traité
Voici comment il faut l'écrire
Le raisonnement est bon mais pas la syntaxe
NB: Le cas ou les cellules sont égales n'est pas traité
Voici comment il faut l'écrire
Sub test() dim i as integer For i = 2 To range("D2").End(xlDown).Row If Cells(i, 4).Value < Cells(i, 5).Value Then Cells(i, 6).Value = "positive" Cells(i, 3).Interior.ColorIndex = 3 Cells(i, 6).Interior.ColorIndex = 3 Else Cells(i, 3).Value = "négative" Cells(i, 3).Interior.ColorIndex = 43 Cells(i, 6).Interior.ColorIndex = 43 End If Next i End Sub
Bonjour,
Je pense que l'ecriture des bloc If .. Then ... EsleIf ... Else .. En If est incorrecte
Voici comment je l'ecrirai moi
ou encore
Personnellement je préfère la seconde, elle est mieux structurée.
En fait chez toi c'est le Else qui pose problème.
Si tu veux conserver ta syntaxe il faut tout mettre sur la meme ligne comme ça:
Else: Cells(i, 3).Value = "en ligne" : Cells(i, 2).Interior.ColorIndex = 50 : Cells(i, 3).Interior.ColorIndex = 50
Un conseil, apprends à structurer tes programmes, la lecture et le déboguage sera plus facile.
A+.
Je pense que l'ecriture des bloc If .. Then ... EsleIf ... Else .. En If est incorrecte
Voici comment je l'ecrirai moi
For i = 3 To range("B3").End(xlDown).Row If Cells(i, 3).Value = "positive" Then Cells(i, 2).Interior.ColorIndex = 50 Cells(i, 3).Interior.ColorIndex = 50 ElseIf Cells(i, 3).Value = "négative" Then Cells(i, 2).Interior.ColorIndex = 3 Cells(i, 3).Interior.ColorIndex = 3 Else Cells(i, 3).Value = "en ligne" Cells(i, 2).Interior.ColorIndex = 50 Cells(i, 3).Interior.ColorIndex = 50 End If Next i
ou encore
For i = 3 To range("B3").End(xlDown).Row If Cells(i, 3).Value = "positive" Then Cells(i, 2).Interior.ColorIndex = 50 Cells(i, 3).Interior.ColorIndex = 50 Else If Cells(i, 3).Value = "négative" Then Cells(i, 2).Interior.ColorIndex = 3 Cells(i, 3).Interior.ColorIndex = 3 End If Else Cells(i, 3).Value = "en ligne" Cells(i, 2).Interior.ColorIndex = 50 Cells(i, 3).Interior.ColorIndex = 50 End If Next i
Personnellement je préfère la seconde, elle est mieux structurée.
En fait chez toi c'est le Else qui pose problème.
Si tu veux conserver ta syntaxe il faut tout mettre sur la meme ligne comme ça:
Else: Cells(i, 3).Value = "en ligne" : Cells(i, 2).Interior.ColorIndex = 50 : Cells(i, 3).Interior.ColorIndex = 50
Un conseil, apprends à structurer tes programmes, la lecture et le déboguage sera plus facile.
A+.
18 juin 2009 à 23:41
19 juin 2009 à 18:37
pouvez vous me dire ce qui cloche avec mon programme ????
Dim i As Integer
Cells(2, 2).Interior.ColorIndex = 25
Cells(2, 5).Interior.ColorIndex = 25
Cells(10, 2).Interior.ColorIndex = 25
Cells(10, 5).Interior.ColorIndex = 25
Cells(18, 5).Interior.ColorIndex = 25
Cells(21, 5).Interior.ColorIndex = 50
Cells(23, 5).Interior.ColorIndex = 3
Cells(22, 5).Interior.ColorIndex = 50
For i = 3 To range("B3").End(xlDown).Row
If Cells(i, 3).Value = "positive" Then
Cells(i, 2).Interior.ColorIndex = 50
Cells(i, 3).Interior.ColorIndex = 50
ElseIf Cells(i, 3).Value = "négative" Then
Cells(i, 2).Interior.ColorIndex = 3
Cells(i, 3).Interior.ColorIndex = 3
Else: Cells(i, 3).Value = "en ligne"
Cells(i, 2).Interior.ColorIndex = 50
Cells(i, 3).Interior.ColorIndex = 50
End If
Next i
For i = 3 To range("E3").End(xlDown).Row
If Cells(i, 6).Value = "positive" Then
Cells(i, 5).Interior.ColorIndex = 50
Cells(i, 6).Interior.ColorIndex = 50
ElseIf Cells(i, 6).Value = "négative" Then
Cells(i, 5).Interior.ColorIndex = 3
Cells(i, 6).Interior.ColorIndex = 3
Else: Cells(i, 6).Value = "en ligne"
Cells(i, 5).Interior.ColorIndex = 50
Cells(i, 6).Interior.ColorIndex = 50
End If
Next i
For i = 11 To range("E11").End(xlDown).Row
If Cells(i, 6).Value = "positive" Then
Cells(i, 5).Interior.ColorIndex = 50
Cells(i, 6).Interior.ColorIndex = 50
ElseIf Cells(i, 6).Value = "négative" Then
Cells(i, 5).Interior.ColorIndex = 3
Cells(i, 6).Interior.ColorIndex = 3
Else: Cells(i, 6).Value = "en ligne"
Cells(i, 5).Interior.ColorIndex = 50
Cells(i, 6).Interior.ColorIndex = 50
End If
Next i
For i = 11 To range("B11").End(xlDown).Row
If Cells(i, 3).Value = "positive" Then
Cells(i, 2).Interior.ColorIndex = 50
Cells(i, 3).Interior.ColorIndex = 50
ElseIf Cells(i, 3).Value = "négative" Then
Cells(i, 2).Interior.ColorIndex = 3
Cells(i, 3).Interior.ColorIndex = 3
Else: Cells(i, 3).Value = "en ligne"
Cells(i, 2).Interior.ColorIndex = 50
Cells(i, 3).Interior.ColorIndex = 50
End If
Next i
For i = 19 To range("E19").End(xlDown).Row
If Cells(19, 6).Value = "positive" Then
Cells(19, 5).Interior.ColorIndex = 50
Cells(19, 6).Interior.ColorIndex = 50
If Cells(19, 6).Value = "négative" Then
Cells(19, 5).Interior.ColorIndex = 3
Cells(19, 6).Interior.ColorIndex = 3
Else: Cells(19, 6).Value = "en ligne"
Cells(19, 5).Interior.ColorIndex = 50
Cells(19, 6).Interior.ColorIndex = 50
End If
Next i
End Sub