'Déclare la variable Mois
Dim Mois As String
Dim k As Integer, L As Long, Col As Integer
'Déclare la variable B et C
Dim B As String
Dim C As Range, X
'changé de méthode,problème avec numfact,pourquoi???
'nomcombobox contiendra nfacture,nanfacture1,etc
If NomClient.Value = "" Or NomCombobox = "" Then Exit Sub
L = NomClient.List(NomClient.ListIndex, 2) 'la ligne du nom
'cherche le n°facture sur la ligne
With Sheets("SAISIE1")
Set C = .Rows(L).Find(Controls(NomCombobox).Value, LookIn:=xlValues)
If Not C Is Nothing Then
'Définit la variable Mois
'c.formula="=JANVIER!E9" ,InStr donne la position de ! dans la chaîne
'd'où mid(2,résultat instr-2) donne le mois voir aide(F1)
Mois = Mid(C.Formula, 2, InStr(C.Formula, "!") - 2) 'extrait le mois
C.Offset(, 1).Font.ColorIndex = 5
C.Offset(, 1).Font.Bold = True
Col = C.Column 'colonne du mois
L = 0
'cherche d'abord le nom,ensuite le n°facture sur la ligne
With Sheets(Mois) 'si tu employes with end with ne pas oublier le point devant cells et /ou range
Set C = .Columns("B").Find(NomClient.Value, LookIn:=xlValues)
If Not C Is Nothing Then
L = C.Row 'index ligne nom
Set C = .Rows(L).Find(Controls(NomCombobox).Value, LookIn:=xlValues)
If Not C Is Nothing Then
C.Offset(0, -1).Font.ColorIndex = 5
C.Offset(, -1).Font.Bold = True 'corrigé
'Renvoie les informations dans la partie "Détail Encaissement " sans le format
.Range("V" & C.Row).Value = Sheets("SAISIE1").Range("B" & Lig).Value
.Range("W" & C.Row).Value = Sheets("SAISIE1").Range("C" & Lig).Value
.Range("X" & C.Row).Value = Sheets("SAISIE1").Range("D" & Lig).Value
.Range("Z" & C.Row).Value = Sheets("SAISIE1").Range("E" & Lig).Value
.Range("Y" & C.Row).Value = Sheets("SAISIE1").Range("F" & Lig).Value
.Range("AA" & C.Row).Value = Sheets("SAISIE1").Range("G" & Lig).Value
.Range("AB" & C.Row).Value = Sheets("SAISIE1").Range("B8").Value
End If
End If
End With
[COLOR="Red"]'Partie qui conserne ma question[/COLOR]
With Sheets(Mois)
Set plage = .Range("E8:E12")
.Range("E18").Value = ""
For Each C In plage
If C.Font.ColorIndex = 5 Then
.Range("E18").Value = .Range("E18") + C.Value
[COLOR="Green"]C.Value=0[/COLOR]
End If
Next C
End With
[COLOR="Red"]' Suite logique de la macro [/COLOR]
With Sheets(Mois)
Set plage = .Range("I8:I12")
.Range("I18").Value = ""
For Each C In plage
If C.Font.ColorIndex = 5 Then
.Range("I18").Value = .Range("I18") + C.Value
End If
Next C
End With
With Sheets(Mois)
Set plage = .Range("M8:M12")
.Range("M18").Value = ""
For Each C In plage
If C.Font.ColorIndex = 5 Then
.Range("M18").Value = .Range("M18") + C.Value
End If
Next C
End With
With Sheets(Mois)
Set plage = .Range("Q8:Q12")
.Range("Q18").Value = ""
For Each C In plage
If C.Font.ColorIndex = 5 Then
.Range("Q18").Value = .Range("Q18") + C.Value
End If
Next C
End With
End If
End With