plusieurs textbox en valeur numerique : module de classe (résolu)

  • Initiateur de la discussion Initiateur de la discussion eideal44
  • Date de début Date de début

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

eideal44

XLDnaute Junior
Bonjour, J'ai plusieurs textbox dans un userform sur excel 2000 et j'ai indiqué pour chaque textbox un code vba afin de n'accepter que la virgule et pouvoir la compléter 2 chiffres après la virgule mais j'aimerais savoir si quelqu'un pourrait m'aider pour réduire le code car il est très long:

'TEXTBOX EN VALEUR NUMERIQUE + 2 CHIFFRES APRES LA VIRGULE
Private Sub Textbox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("1234567890,-", Chr(KeyAscii)) = 0 Or Textbox1.SelStart > 0 And Chr(KeyAscii) = "-" _
Or InStr(Textbox1.Value, ",") <> 0 And Chr(KeyAscii) = "," Then
KeyAscii = 0: Beep
End If
If Right(Textbox1, 1) = "." Or Right(Textbox1, 1) = "," Then
Textbox1.MaxLength = Len(Textbox1) + 2
End If
End Sub

Private Sub Textbox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("1234567890,-", Chr(KeyAscii)) = 0 Or Textbox2.SelStart > 0 And Chr(KeyAscii) = "-" _
Or InStr(Textbox2.Value, ",") <> 0 And Chr(KeyAscii) = "," Then
KeyAscii = 0: Beep
End If
If Right(Textbox2, 1) = "." Or Right(Textbox2, 1) = "," Then
Textbox2.MaxLength = Len(Textbox2) + 2
End If
End Sub

Private Sub Textbox3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("1234567890,-", Chr(KeyAscii)) = 0 Or Textbox3.SelStart > 0 And Chr(KeyAscii) = "-" _
Or InStr(Textbox3.Value, ",") <> 0 And Chr(KeyAscii) = "," Then
KeyAscii = 0: Beep
End If
If Right(Textbox3, 1) = "." Or Right(Textbox3, 1) = "," Then
Textbox3.MaxLength = Len(Textbox3) + 2
End If
End Sub

Private Sub Textbox4_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr("1234567890,-", Chr(KeyAscii)) = 0 Or Textbox4.SelStart > 0 And Chr(KeyAscii) = "-" _
Or InStr(Textbox4.Value, ",") <> 0 And Chr(KeyAscii) = "," Then
KeyAscii = 0: Beep
End If
If Right(Textbox4, 1) = "." Or Right(Textbox4, 1) = "," Then
Textbox4.MaxLength = Len(Textbox4) + 2
End If
End Sub

-------------------------

de plus j'aimerais savoir si il existe un code pour que quand on quitte un textbox celui se mette automatiquement 2 chiffres après la virgule (ex: notez 99 dans un textbox et dès qu'on passe au 2ième, ça inscrit 99,00).

dans l'attente de vos lumières car je galère un peu

FRED
 
Dernière édition:
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
2
Affichages
423
Retour