TheProdigy
XLDnaute Impliqué
Bonjour out le monde,
Je voudrais avoir une saisi dans un texbox de type 12552-A-12 en code VBA
Merci
Je voudrais avoir une saisi dans un texbox de type 12552-A-12 en code VBA
Merci
Dernière édition:
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
Private Sub TextBox1_KeyPress(ByVal K As MSForms.ReturnInteger)
Select Case Len(TextBox1)
Case 0 To 4, 8, 9
Select Case K
Case 48 To 57: Case Else: K = 0
End Select
Case 5, 7: K = 95
Case 6
Select Case K
Case 65 To 90: Case Else: K = 0
End Select
Case Is > 9: K = 0
End Select
End Sub