Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) nbdec = 2 '==============ici le nb de décimales admises pos = InStr(TextBox1.Text, ",") If pos > 0 And Chr(KeyAscii) "," Then KeyAscii 0: Exit Sub If Not IsNumeric(Chr(KeyAscii)) And Chr(KeyAscii) <> "," Then KeyAscii = 0: Exit Sub If pos = 0 Then Exit Sub If Len(Mid(TextBox1.Text & Chr(KeyAscii), pos + 1)) > nbdec Then KeyAscii = 0 End Sub
If ubound(Split(MaTxtBox.Text,","))>1 then 'Trop de , ElseIf ubound(Split(MaTxtBox.Text,","))=1 Then If Len(Split(MaTxtBox.Text,",")(1))>2 Then 'Trop de chiffre End If End If
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionIf InStr("1234567890,", Chr(KeyAscii)) 0 Or InStr(Valeur.Value, ",") <> 0 And Chr(KeyAscii) "," Then KeyAscii = 0: End if
If InStr("1234567890,", Chr(KeyAscii)) 0 then keyscii 0
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger) nbdec = 2 '==============ici le nb de décimales admises pos = InStr(TextBox1.Text, ",") If pos > 0 And Chr(KeyAscii) "," Then KeyAscii 0: Exit Sub If Not IsNumeric(Chr(KeyAscii)) And Chr(KeyAscii) <> "," Then KeyAscii = 0: Exit Sub toto = TextBox1.Text & Chr(KeyAscii) If pos > 0 And Len(Mid(toto, pos + 1)) > nbdec Or toto "," Then KeyAscii 0 End Sub
Private Sub TextBox1_Change() Static anc As String nbdec = 2 '==============ici le nb de décimales admises pos = InStr(TextBox1.Text, ",") toto = TextBox1.Text If Not IsNumeric(toto) Or toto Like "*[A-z]*" Then If toto <> "" Then TextBox1.Text anc Else anc "" Else If pos > 0 Then If Len(Mid(toto, pos + 1)) > nbdec Then TextBox1.Text = anc Else anc = toto End If End If End If End Sub
Dim St As String If InStr(1, TextBox1.Text, ",") > 0 Then St = "0123456789" Else St = "0123456789," End If If InStr(St, Chr(KeyAscii)) 0 Then keyscii 0
Dim St As String Dim Rt As Integer Rt = InStr(1, TextBox1.Text, ",") If Rt > 0 Then St = "0123456789" Else St = "0123456789," End If If (Rt > 0 And Len(TextBox1.Text) > Rt + 1) Or InStr(St, Chr(KeyAscii)) 0 Then KeyAscii 0
If (Chr(KeyAscii) = "," And Len(Textbox1.Text) = 0) Or (Rt > 0 And Len(Textbox1.Text) > Rt + 1) Or InStr(St, Chr(KeyAscii)) = 0 Then KeyAscii = 0
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean) TextBox1.Text = Format(TextBox1.Text, "### ###.00") End Sub