Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
Dim plage As Single
If TextBox1 = "" Then Exit Sub
plage = TextBox1
If plage < 1 Or plage > 100 Then
Cancel = True
MsgBox "Données non valide ! La valeur doit être comprise entre 1 et 100"
TextBox1 = ""
End If
End Sub
Private Sub TextBox1_Change()
Dim vMax
vMax = 100
If TextBox1 = vbNullString Then Exit Sub
If Not IsNumeric(TextBox1) Then
MsgBox "Ne saisir que des chiffres! Merci", vbCritical
TextBox1 = vbNullString
ElseIf Val(TextBox1) > vMax Then
MsgBox "Valeur incorrecte!", vbCritical
TextBox1 = 100
End If
End Sub
Private Sub TextBox1_Change()
TextBox1 = Left(TextBox1, 3)
If Not IsNumeric(Mid(TextBox1, 1, 1)) Then TextBox1 = Mid(TextBox1, 2)
If Not IsNumeric(Mid(TextBox1, 2, 1)) Then TextBox1 = Left(TextBox1, 1) & Mid(TextBox1, 3)
If Not IsNumeric(Mid(TextBox1, 3, 1)) Then TextBox1 = Left(TextBox1, 2)
If Val(Left(TextBox1, 3)) > 100 Then TextBox1 = Left(TextBox1, 2)
End Sub
Private Sub TextBox1_Change()
TextBox1 = Left(TextBox1, 3)
If Not IsNumeric(Mid(TextBox1, 1, 1)) Then TextBox1 = Mid(TextBox1, 2)
If Not IsNumeric(Mid(TextBox1, 2, 1)) Then TextBox1 = Left(TextBox1, 1) & Mid(TextBox1, 3)
If Not IsNumeric(Mid(TextBox1, 3, 1)) Or Val(TextBox1) > 100 Then TextBox1 = Left(TextBox1, 2)
End Sub
Private Sub TextBox1_Change()
Private Sub TextBox1_Change()
If TextBox1 > 100 Then
Cancel = True
TextBox1 = "Uniquement valeur" & vbCrLf & "numérique < à 100"
With TextBox1
.SetFocus
.SelStart = 0
.SelLength = Len(TextBox1.Text)
End With
End If
End Sub
End Sub
MERCI C'EST SUPERBonjour le fil,
Une autre possibilité
VB:Private Sub TextBox1_Change() Dim vMax vMax = 100 If TextBox1 = vbNullString Then Exit Sub If Not IsNumeric(TextBox1) Then MsgBox "Ne saisir que des chiffres! Merci", vbCritical TextBox1 = vbNullString ElseIf Val(TextBox1) > vMax Then MsgBox "Valeur incorrecte!", vbCritical TextBox1 = 100 End If End Sub
DEAR Job75Evidemment ceci est mieux :
VB:Private Sub TextBox1_Change() TextBox1 = Left(TextBox1, 3) If Not IsNumeric(Mid(TextBox1, 1, 1)) Then TextBox1 = Mid(TextBox1, 2) If Not IsNumeric(Mid(TextBox1, 2, 1)) Then TextBox1 = Left(TextBox1, 1) & Mid(TextBox1, 3) If Not IsNumeric(Mid(TextBox1, 3, 1)) Or Val(TextBox1) > 100 Then TextBox1 = Left(TextBox1, 2) End Sub
Private Sub TextBox1_Change()
With TextBox1
.Value = Replace(.Value, ".", ",") ' on accepte les décimales
If .Value > 100 Or Not IsNumeric(.Value) Then
Cancel = True
.Value = IIf(.Value <> "", "Uniquement valeur numérique < à 100", "")
.SetFocus
.SelStart = 0
.SelLength = Len(.Value)
End If
End With
End Sub