Pierre, le forum
Pris sur la toile de docm:
Dim Arriere As Boolean
Const SeparateurTextbox1 = ":"
Const NbrDeSeparateursTextbox1 = 1
Const CaracteresPermis = "0123456789"
Private Sub TextBox1_Change()
'Entrée progressive d'une date de format "00:00"
Dim i, SuiteDeCaracteres, texte, separateur
If Arriere = True Then
Arriere = False
Exit Sub
End If
If TextBox1.SelStart <> Len(TextBox1.Text) Then
Exit Sub
End If
For i = 1 To Len(TextBox1.Text)
If InStr(CaracteresPermis, Mid(TextBox1.Text, i, 1)) Then
SuiteDeCaracteres = SuiteDeCaracteres + 1
texte = texte & Mid(TextBox1.Text, i, 1)
Else
SuiteDeCaracteres = 0
separateur = separateur + 1
texte = texte & Mid(TextBox1.Text, i, 1)
End If
Next
If separateur < NbrDeSeparateursTextbox1 Then
If SuiteDeCaracteres = 2 Then
texte = texte & SeparateurTextbox1
End If
End If
TextBox1.MaxLength = 5
TextBox1.Value = texte
End Sub
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
If KeyCode = 8 Then
Arriere = True
End If
End Sub
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
A = Chr(KeyAscii)
If InStr(SeparateurTextbox1 & CaracteresPermis, A) = 0 Then
KeyAscii = 0
End If
End Sub
Salut, G'Claire