Private Sub TextBox1_Change()
Dim x$, mes
x = TextBox1
x = Replace(x, "-", "")
If IsNumeric(Left(x, 1)) Then
If Len(x) > 4 Then x = Application.Replace(x, 5, 0, "-")
If Len(x) > 7 Then x = Application.Replace(x, 8, 0, "-")
x = UCase(Left(x, 10))
If Len(x) = 10 Then If Not x Like "####-[A-Z][A-Z]-##" Then mes = "Le format doit être 0000-AA-00"
Else
If Len(x) > 2 Then x = Application.Replace(x, 3, 0, "-")
If Len(x) > 6 Then x = Application.Replace(x, 7, 0, "-")
x = UCase(Left(x, 9))
If Len(x) = 9 Then If Not x Like "[A-Z][A-Z]-###-[A-Z][A-Z]" Then mes = "Le format doit être AA-000-AA"
End If
TextBox1 = x
If mes <> "" Then MsgBox mes
End Sub