Bonjour,
Ma demande concerne l'allègement de mon code. Mon programme est muni de plusieurs UserForm contenant également plusieurs TextBox.
Les TextBox concernées possèdent un code obligeant l'entrée de valeurs numériques.
J'ai donc par exemple :
Private Sub TextBox2_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr(1, "0123456789.,", Chr(KeyAscii)) = 0 And KeyAscii <> 8 Then
MsgBox "Caractère non autorisé, chiffres uniquement", vbExclamation
KeyAscii = 0
End If
End Sub
Private Sub TextBox3_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr(1, "0123456789.,", Chr(KeyAscii)) = 0 And KeyAscii <> 8 Then
MsgBox "Caractère non autorisé, chiffres uniquement", vbExclamation
KeyAscii = 0
End If
End Sub
Private Sub TextBox6_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr(1, "0123456789.,", Chr(KeyAscii)) = 0 And KeyAscii <> 8 Then
MsgBox "Caractère non autorisé, chiffres uniquement", vbExclamation
KeyAscii = 0
End If
End Sub
Private Sub TextBox8_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If InStr(1, "0123456789.,", Chr(KeyAscii)) = 0 And KeyAscii <> 8 Then
MsgBox "Caractère non autorisé, chiffres uniquement", vbExclamation
KeyAscii = 0
End If
End Sub
Je rentre le code pour chaque TextBox ce qui me parait être lourd et je pense qu'il y a possibilité d'alléger tout cela sachant que pour chaque UserForm cela concerne entre 10 et 15 TextBox.
Je vous remercie d'avance pour vos réponses !