1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| Option Explicit
Const entrees_decimales_permises = ".,0123456789" & vbCr & vbBack
Const Point = "."
Const Virgule = ","
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
Dim Pos As Long
If KeyAscii = Asc(Virgule) Then
If InStr(TextBox1, Point) = 0 Then
KeyAscii = Asc(Point)
Else
KeyAscii = 0
End If
ElseIf InStr(entrees_decimales_permises, Chr(KeyAscii)) = 0 Then
KeyAscii = 0
ElseIf InStr(TextBox1, Point) > 0 And KeyAscii = Asc(Point) Then
KeyAscii = 0
ElseIf InStr(TextBox1, Point) > 0 Then
Pos = InStr(TextBox1.Text, Point)
If Len(TextBox1.Text) = Pos + 2 Then
TextBox1.Text = Left$(TextBox1.Text, Len(TextBox1.Text) - 1)
End If
End If
End Sub |
Partager