Sub AjoutAchat()
  Dim MtAchat As Double, MtRemise As Double
  Dim Na As Integer, DLigA As Long
  ' Récupérer la ligne de sélection
  Lig = Selection.Row
  '
  ' Tester le numéro de ligne
  If Lig <= 2 Then
    ' Si ligne d'entête on prévient et on sort
    MsgBox "Sélectionner une ligne de client - Vous êtes sur la zone de filtre", vbInformation, "ATTENTION .."
    Exit Sub
  End If
  ' Mémoriser le nom du client
  NomClt = Range("A" & Lig) & " " & Range("B" & Lig)
  '
  ' Tester le nom du client
  If Len(NomClt) = 1 Then
    ' Si aucun nom de client sur la ligne
    MsgBox "Merci de sélectionner une ligne avec un nom de client", vbInformation, "ATTENTION ..."
    Exit Sub
  End If
  ' Mémoriser le numéro de colonne
  NCol = Cells(Lig, Columns.Count).End(xlToLeft).Column + 1
  MtAchat = Application.WorksheetFunction.SumIf(Range("D2:W2"), "Montant", Range("D" & Lig & ":W" & Lig))
  MtRemise = Round(MtAchat * 5 / 100)
  ' Si le total des achats atteint 200 € = le client à droit à 10 € de remise
  If MtAchat >= 200 Then
    ' Afficher le message
    MsgBox "Le client à droit à 10 € de remise" & vbCr _
         & "Montant total achat = " & Format(MtAchat, "#,##0.00") & vbCr _
         & "Remise = " & Format(MtRemise, "#,##0.00"), vbInformation, "REMISE ACCORDEE"
    ' Inscrire le montant sur la ligne
    Range("X" & Lig).Value = Format(Now(), "mm/dd/yyyy")
    Range("Y" & Lig).Value = MtRemise
    ' On archive les achats du client
    DLigA = Sheets("Archives").Range("A" & Rows.Count).End(xlUp).Row
    Sheets("BdDClt").Range("A" & Lig & ":Y" & Lig).Copy _
        Destination:=Sheets("Archives").Range("A" & DLigA + 1)
    Range("D" & Lig & ":Y" & Lig).ClearContents
  Else
    For Na = 4 To 23 Step 2
      If Cells(Lig, Na) = "" Then
        MsgBox "Actuellement, il reste " & 200 - MtAchat & " € d'achats à effectuer" & vbCr _
             & "Montant total achat = " & Format(MtAchat, "#,##0.00") & vbCr _
             & "Remise = " & Format(MtRemise, "#,##0.00"), vbInformation, "REMISE POTENTIELLE"
        Exit For
      End If
    Next
    UsF_Achat.Show
  End If
End Sub
