Sub coul()
With Selection
For lig = 1 To .Rows.Count
If .Cells(lig, 1) & .Cells(lig, 2) <> .Cells(lig - 1, 1) & .Cells(lig - 1, 2) Then cpt = cpt + 1
If cpt Mod 2 = 1 Then .Cells(lig, 1).Resize(1, 3).Interior.ColorIndex = 6
Next lig
End With
End Sub
Sub Gourdin()
Dim i As Long, AColorer As Boolean
AColorer = True
With Worksheets("Feuil1") ' à adapter
For i = 3 To .Range("B" & Rows.Count).End(xlUp).Row
If AColorer = True Then .Cells(i, 2).Resize(1, 3).Interior.ColorIndex = 6
If Not (.Cells(i, 2) = .Cells(i + 1, 2) And .Cells(i, 3) = .Cells(i + 1, 3)) Then AColorer = Not AColorer
Next
End With
End Sub
Bonjour gourdin,
Une solution (parmi bien d'autres)...
Attention: sélectionner la plage de cellules concernée au préalable. On verra par la suite, avec plus d'infos comment repérer la plage sans la sélectionner.
Coller dans la fenêtre de code de la Feuil1:
VB:Sub coul() With Selection For lig = 1 To .Rows.Count If .Cells(lig, 1) & .Cells(lig, 2) <> .Cells(lig - 1, 1) & .Cells(lig - 1, 2) Then cpt = cpt + 1 If cpt Mod 2 = 1 Then .Cells(lig, 1).Resize(1, 3).Interior.ColorIndex = 6 Next lig End With End Sub
bonjour gourdin, Modeste,
une autre version (sans sélection)
Code:Sub Gourdin() Dim i As Long, AColorer As Boolean AColorer = True With Worksheets("Feuil1") ' à adapter For i = 3 To .Range("B" & Rows.Count).End(xlUp).Row If AColorer = True Then .Cells(i, 2).Resize(1, 3).Interior.ColorIndex = 6 If Not (.Cells(i, 2) = .Cells(i + 1, 2) And .Cells(i, 3) = .Cells(i + 1, 3)) Then AColorer = Not AColorer Next End With End Sub
A+
Bonjour Modeste
Merci pour cette solution qui me convient parfaitement (je me débrouille pour sélectionner la plage)
Bonjour RachidBonjour @ tous,
avec une MFC
voir PJ
@ + +
If cpt Mod 2 = 1
Sub coul()
With [B3].Resize([B3].CurrentRegion.Rows.Count - 1, [B3].CurrentRegion.Columns.Count)
.Interior.ColorIndex = xlNone
For lig = 1 To .Rows.Count
If .Cells(lig, 1) & .Cells(lig, 2) <> .Cells(lig - 1, 1) & .Cells(lig - 1, 2) Then cpt = cpt + 1
If cpt Mod 2 = 0 Then .Cells(lig, 1).Resize(1, 3).Interior.ColorIndex = 6
Next lig
End With
End Sub
J'ai failli le mentionner au passage ... mais je n'ai pas oséDans ma proposition, pour commencer la mise en couleur au deuxième bloc, modifier
AColorer = True par AColorer = False (ou bien supprimer la ligne)
=EST.IMPAIR(SOMME((($B$3:$B3<>$B$2:$B2)+($C$3:$C3<>$C$2:$C2)>0)*LIGNE($B$3:$B3)/LIGNE($B$3:$B3)))