Dim Longueur As Integer
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
Longueur = Len(TextBox1.Text)
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Select Case Longueur
Case 0 To 5, 9, 10
Select Case KeyAscii
Case 48 To 57: Case Else: KeyAscii = 0
End Select
Case 6, 8: KeyAscii = 95 'rajoute le tiret bas quelle que soit la touche appuyée
Case 7
Select Case KeyAscii
Case 65 To 90: Case Else: KeyAscii = 0
End Select
Case Is > 10: KeyAscii = 0
End Select
End Sub