Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("0123456789,-.", Chr(KeyAscii)) = 0 Or TextBox1.SelStart > 0 And Chr(KeyAscii) = "-" Or InStr(TextBox1.Value, ",") <> 0 And Chr(KeyAscii) = "," Or InStr(TextBox1.Value, ".") <> 0 And Chr(KeyAscii) = "." Then KeyAscii = 0: Beep
End Sub
Autorise une seule virgule ou un seul point (Faut-il ajouter "interdire virgule si point" et "interdire point si virgule" ?)
Autorise aussi seulement le signe "-" au début du nombre.
Tiens nous au courant et
EDITION :
Alternative avec "Interdit de mettre un point si il y a une virgule déjà" et "interdit de mettre une virgule si il y a un point déjà"
Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("0123456789,-.", Chr(KeyAscii)) = 0 Or TextBox1.SelStart > 0 And Chr(KeyAscii) = "-" Or InStr(TextBox1.Value, ",") <> 0 And Chr(KeyAscii) = "," Or InStr(TextBox1.Value, ".") <> 0 And Chr(KeyAscii) = "." Or InStr(TextBox1.Value, ".") <> 0 And Chr(KeyAscii) = "," Or InStr(TextBox1.Value, ",") <> 0 And Chr(KeyAscii) = "." Then KeyAscii = 0: Beep
End Sub
Cordialement,
Avie.