Private Sub VALID_Click()
Dim nLigne As String, rgDate As Range, Rep As Long
Dim tDate, S As String, i As Long, N, LaDate As Date
'Vérif saisie d'une date valide
tDate = Split(TextBox1, "/")
For i = LBound(tDate) To UBound(tDate)
S = S & tDate(i) & IIf(i = UBound(tDate), "", "/")
Next i
If Not IsDate(S) Or UBound(tDate) <> 2 Then
MsgBox "Veuillez rentrer une date valide..."
TextBox1.SetFocus
Exit Sub
Else
LaDate = DateValue(CDate(TextBox1))
End If
'Vérif saisie d'un taux valide
TextBox2 = Replace(TextBox2, ".", Mid(Val("1.1"), 2, 1))
If Not IsNumeric(TextBox2) Then
MsgBox "Veuillez saisir un taux valide!"
TextBox2.SetFocus
Exit Sub
Else
N = 0 + TextBox2
End If
'Recherche de la date
Set rgDate = Nothing
Set rgDate = Range("A:A").Find(what:=LaDate)
If rgDate Is Nothing Then
'la date n'existe pas
nLigne = Cells(Rows.Count, "a").End(xlUp).Row
If Not Cells(nLigne, "a") = "" Then nLigne = nLigne + 1
Cells(nLigne, "a") = LaDate
Cells(nLigne, "b") = N
Else
' la date existe
Rep = MsgBox("La date existe déjà avec un taux de: " & _
rgDate.Offset(, 1) & vbLf & vbLf & _
"Voulez-vous remplacer l'ancien taux par: " & N, _
Buttons:=vbInformation + vbYesNo + vbDefaultButton1)
If Rep = vbYes Then rgDate.Offset(, 1) = N
End If
End Sub