Private Sub CommandButton1_Click() 'contrôle
Application.ScreenUpdating = False 'gain de temps pas d'affichage
'declaration des variables'
Dim i As Long, col As Integer, nb As Byte, j As Integer, derlig As Long
'initialisation de la variable nombre'
nb = 0
'recherche de la dernière ligne de la feuille'
derlig = Range("A" & Rows.Count).End(xlUp).Row
'boucle de la ligne 4 à la dernière ligne'
For i = 4 To derlig
'si la cellule de la 1ère colonne n'est pas vide
If Len(Range("A" & i).Value) > 0 Then
'boucle de la colonne 2 à 32'
For col = 2 To 32
'si la cellule est = à JT
If Cells(i, col).Value = "JT" Then
nb = nb + 1 'nombre =nombre +1
'colorie la cellule en jaune
Cells(i, col).Interior.ColorIndex = 6
Else 'sinon'
nb = 0 'reinitialise le nombre
'colorie les cellules en fonction de leur contenu
Select Case UCase(Cells(i, col).Value)
Case Is = "JRS"
Cells(i, col).Interior.ColorIndex = 17
Case Is = "CP"
Cells(i, col).Interior.ColorIndex = 4
Case Is = "EF"
Cells(i, col).Interior.ColorIndex = 8
Case Is = "DEP"
Cells(i, col).Interior.ColorIndex = 7
Case Is = "CFA"
Cells(i, col).Interior.ColorIndex = 22
Case Is = "N/A" 'efface les cellules contenant N/A'
Cells(i, col).ClearContents
End Select
End If
If nb > 5 Then 'si nombre >5'
If col + 1 - nb > 2 Then 'si c'est sur la même ligne
Range(Cells(i, col + 1 - nb), Cells(i, col)).Interior.ColorIndex = 3
Else 'sinon recherche de la dernière cellule de la ligne précédente'
j = 32
While Cells(i - 1, j).Value <> "JT"
j = j - 1
Wend 'colorie la ligne précédente'
Range(Cells(i - 1, j - nb + col), Cells(i - 1, j)).Interior.ColorIndex = 3
'et la ligne suivante'
Range(Cells(i, 2), Cells(i, col)).Interior.ColorIndex = 3
End If
End If
Next
Else
nb = 0
End If
Next
Application.ScreenUpdating = True 'remet l'affichage