Public Sub toto()
Dim plg As Range
Set plg = Selection
If Application.CountA(plg) = 0 Then
MsgBox ("Sélection vide")
Else
MsgBox ("Sélection non vide")
End If
End Sub
Sub toto()
Dim nr&, r&, v&, Cel As Range
With Selection
For Each Cel In .Cells
If Cel.Value = "" Then v = v + 1 Else Exit For
Next
If v = .Cells.Count Then _
MsgBox "Toutes les cellules de la selection (" & .Address(0, 0) & ") contiennent """"." Else _
MsgBox "Au moins une cellule de la selection (" & .Address(0, 0) & ") ne contient pas """"."
For Each Cel In .Cells
If Cel.Interior.ColorIndex <> 3 Then r = r + 1 Else Exit For
Next
If r = .Cells.Count Then _
MsgBox "Aucune cellule de la selection (" & .Address(0, 0) & ") n'a un fond rouge." Else _
MsgBox "Au moins une cellule de la selection (" & .Address(0, 0) & ") a un fond rouge."
For Each Cel In .Cells
If Cel.Interior.ColorIndex = 3 Then nr = nr + 1
Next
If nr = 0 Then _
MsgBox "Aucune cellule de la selection (" & .Address(0, 0) & ") n'a un fond rouge." Else _
MsgBox nr & " cellule" & IIf(nr > 1, "s", "") & " de la selection (" & .Address(0, 0) & ") " & IIf(nr > 1, "ont", "a") & " un fond rouge."
If r = .Cells.Count And v = .Cells.Count Then _
MsgBox "Aucune cellule de la selection (" & .Address(0, 0) & ") n'a un fond rouge" & vbLf & "et toutes les cellules de la selection contiennent """"." Else _
MsgBox "Au moins une cellule de la selection (" & .Address(0, 0) & ") a un fond rouge" & vbLf & "ou ne contient pas """"."
End With
End Sub
J'aurais donc besoin de changer toutes les lignes rouge en gris avec le bouton ci-dessus
Private Sub CommandButton2_Click()
'remet toutes lignes en blanc
Range(Cells(11, 2), Cells(100, 5)).Interior.ColorIndex = -4142
End Sub
et d’empêcher qu'une ligne devienne rouge si elle est complétement vide
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim plg As Range
Dim c As Range
Dim cpt As Byte
If Not Application.Intersect(Target, Range("B11:e100")) Is Nothing Then
Set plg = Range(Cells(Target.Row, 2), Cells(Target.Row, 5))
'teste si cellule sans valeur
For Each c In plg
If c = 0 Then cpt = cpt + 1
Next c
' si pas de valeur on sort
If cpt = 4 Then
TextBox2 = ""
TextBox2.Activate
Exit Sub
End If
'sinon on gêre la couleur
With plg
If .Interior.ColorIndex = -4142 Then
.Interior.ColorIndex = 3
Else
.Interior.ColorIndex = -4142
End If
End With
End If
TextBox2 = ""
TextBox2.Activate
End Su
Private Sub worksheet_beforedoubleclick(ByVal target As Range, cancel As Boolean)