1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| Sub Affichge_Artisan()
Dim DerLig As Long, i As Long, Nb As Long
Dim Artisan As String
Dim Cell As Range
Application.ScreenUpdating = False
Artisan = Range("D3").Value
Cells.EntireRow.Hidden = False ' on affiche toutes les lignes masquées
DerLig = Range("D" & Rows.Count).End(xlUp).Row
Range("G5:BG" & DerLig).Font.ColorIndex = 2 'on passe toutes les polices de la plage en blanc
For i = 7 To DerLig Step 3
Nb = Application.WorksheetFunction.CountIf(Range("G" & i & ":BG" & i), Artisan)
If Nb <> 0 Then
For Each Cell In Range("G5:BG" & DerLig)
Rows(i - 2).EntireRow.Hidden = True 'on masque la première ligne de chaque
If Cells(i, Cell.Column) = Artisan Then 'si l'artisan existe
Range(Cells(i - 1, Cell.Column), Cells(i, Cell.Column)).Font.ColorIndex = 1 'on met la police en noir
Nb = Nb - 1 'on décompte
If Nb = 0 Then Exit For 'on passe au test suivant dès que tout le nombre d'artisan trouvé est atteint
End If
Next Cell 'on teste la cellule suivante
Else
Range(i - 2 & ":" & i).EntireRow.Hidden = True 'si l'artisan recherché n'esiste pas sur la ligne, alors on masque les 3 lignes
End If
Next i
End Sub |
Partager