decimal value in the textbox.
Author Message
decimal value in the textbox.

Excel 2000

With thanks to Chip Pearson I make this code and it works good only I don't
want that it is possible to put a decimal value in the textbox.
Now for example 3,34 is possible.

Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(txtb) Then
If txtb < 1 Or txtb > 7 Then Cancel = True

End If
If Not IsNumeric(txtb) Then Cancel = True
End Sub

Regards Ron

Wed, 18 Jun 1902 08:00:00 GMT
decimal value in the textbox.
You might try something like this:

Private Sub txtb_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
If KeyAscii < Asc("0") Or KeyAscii > Asc("9") Then
KeyAscii = 0
End If
End Sub

You can replace Asc("0") and Asc("9") with the actual keycode numbers.

Reagards,
Tom Ogilvy

Quote:
> Excel 2000

> With thanks to Chip Pearson I make this code and it works good only I
don't
> want that it is possible to put a decimal value in the textbox.
> Now for example 3,34 is possible.

> Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> If IsNumeric(txtb) Then
> If txtb < 1 Or txtb > 7 Then Cancel = True

> End If
> If Not IsNumeric(txtb) Then Cancel = True
> End Sub

> Regards Ron

Wed, 18 Jun 1902 08:00:00 GMT
decimal value in the textbox.

If IsNumeric(txtb) Then
If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
Else
Cancel = True
End If
If Cancel Then MsgBox "Must be an integer between 1 and 7."

Rob Rutherford

Quote:

> Excel 2000

> With thanks to Chip Pearson I make this code and it works good only I
don't
> want that it is possible to put a decimal value in the textbox.
> Now for example 3,34 is possible.

> Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> If IsNumeric(txtb) Then
> If txtb < 1 Or txtb > 7 Then Cancel = True

> End If
> If Not IsNumeric(txtb) Then Cancel = True
> End Sub

> Regards Ron

Wed, 18 Jun 1902 08:00:00 GMT
decimal value in the textbox.
Hi Ron,

Next to all the others, here's another one:

If Not IsNumeric(TextBox1) Then Cancel = True: Exit Sub
Cancel = ((CInt(TextBox1) < 1 Or CInt(TextBox1) > 7) Xor _
((CInt(TextBox1) - TextBox1) < 0) Xor _
(Not IsNumeric(TextBox1)))

Just exchanging ideas here.
Perry

Quote:

> Excel 2000

> With thanks to Chip Pearson I make this code and it works good only I
don't
> want that it is possible to put a decimal value in the textbox.
> Now for example 3,34 is possible.

> Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> If IsNumeric(txtb) Then
> If txtb < 1 Or txtb > 7 Then Cancel = True

> End If
> If Not IsNumeric(txtb) Then Cancel = True
> End Sub

> Regards Ron

Wed, 18 Jun 1902 08:00:00 GMT
decimal value in the textbox.
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If Not IsNumeric(TextBox1) Then Cancel = True: Exit Sub
Cancel = ((CInt(TextBox1) < 1 Or CInt(TextBox1) > 7) Xor _
((CInt(TextBox1) - TextBox1) < 0))
End Sub

Quote:
> Hi Ron,

> Next to all the others, here's another one:

>   If Not IsNumeric(TextBox1) Then Cancel = True: Exit Sub
>   Cancel = ((CInt(TextBox1) < 1 Or CInt(TextBox1) > 7) Xor _
>     ((CInt(TextBox1) - TextBox1) < 0) Xor _
>     (Not IsNumeric(TextBox1)))

> Just exchanging ideas here.
> Perry

> > Excel 2000

> > With thanks to Chip Pearson I make this code and it works good only I
> don't
> > want that it is possible to put a decimal value in the textbox.
> > Now for example 3,34 is possible.

> > Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> > If IsNumeric(txtb) Then
> > If txtb < 1 Or txtb > 7 Then Cancel = True

> > End If
> > If Not IsNumeric(txtb) Then Cancel = True
> > End Sub

> > Regards Ron

Wed, 18 Jun 1902 08:00:00 GMT
decimal value in the textbox.

Quote:
> Excel 2000

> With thanks to Chip Pearson I make this code and it works good only I
don't
> want that it is possible to put a decimal value in the textbox.
> Now for example 3,34 is possible.

> Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> If IsNumeric(txtb) Then
> If txtb < 1 Or txtb > 7 Then Cancel = True

> End If
> If Not IsNumeric(txtb) Then Cancel = True
> End Sub

> Regards Ron

Wed, 18 Jun 1902 08:00:00 GMT
decimal value in the textbox.

Hi Rob I like your code the most but If you use the msgbox then you lost the
focus on the textbox.
Do you now a solution.

Ron

Quote:

> If IsNumeric(txtb) Then
>     If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
> Else
>     Cancel = True
> End If
> If Cancel Then MsgBox "Must be an integer between 1 and 7."

> Rob Rutherford

> > Excel 2000

> > With thanks to Chip Pearson I make this code and it works good only I
> don't
> > want that it is possible to put a decimal value in the textbox.
> > Now for example 3,34 is possible.

> > Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> > If IsNumeric(txtb) Then
> > If txtb < 1 Or txtb > 7 Then Cancel = True

> > End If
> > If Not IsNumeric(txtb) Then Cancel = True
> > End Sub

> > Regards Ron

Wed, 18 Jun 1902 08:00:00 GMT
decimal value in the textbox.
Ron,

I tried it in Excel 97 on a user form with a text box and a command button.
If I enter 99 in the text box and click the button the message displays and
the focus remains in the text box. How do you invoke the txtb_Exit event?

Rob Rutherford

Quote:

> Hi Rob I like your code the most but If you use the msgbox then you lost
the
> focus on the textbox.
> Do you now a solution.

> Ron

> > If IsNumeric(txtb) Then
> >     If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
> > Else
> >     Cancel = True
> > End If
> > If Cancel Then MsgBox "Must be an integer between 1 and 7."

> > Rob Rutherford

> > > Excel 2000

> > > With thanks to Chip Pearson I make this code and it works good only I
> > don't
> > > want that it is possible to put a decimal value in the textbox.
> > > Now for example 3,34 is possible.

> > > Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> > > If IsNumeric(txtb) Then
> > > If txtb < 1 Or txtb > 7 Then Cancel = True

> > > End If
> > > If Not IsNumeric(txtb) Then Cancel = True
> > > End Sub

> > > Regards Ron

Wed, 18 Jun 1902 08:00:00 GMT
decimal value in the textbox.

Hi Rob

I said it the wrong way maybe.
The textbox has the focus but the cursor is not in it.
So I can type somthing else before I click on the textbox.

Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(txtb) Then
If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
Else
Cancel = True
End If
If Cancel Then MsgBox "Must be an integer between 1 and 7."
End Sub

Quote:
> Ron,

> I tried it in Excel 97 on a user form with a text box and a command
button.
> If I enter 99 in the text box and click the button the message displays
and
> the focus remains in the text box. How do you invoke the txtb_Exit event?

> Rob Rutherford

> > Hi Rob I like your code the most but If you use the msgbox then you lost
> the
> > focus on the textbox.
> > Do you now a solution.

> > Ron

> > > If IsNumeric(txtb) Then
> > >     If txtb < 1 Or txtb > 7 Or txtb - Int(txtb) > 0 Then Cancel = True
> > > Else
> > >     Cancel = True
> > > End If
> > > If Cancel Then MsgBox "Must be an integer between 1 and 7."

> > > Rob Rutherford

> > > > Hello Newsgroupreaders
> > > > Excel 2000

> > > > With thanks to Chip Pearson I make this code and it works good only
I
> > > don't
> > > > want that it is possible to put a decimal value in the textbox.
> > > > Now for example 3,34 is possible.

> > > > Private Sub txtb_Exit(ByVal Cancel As MSForms.ReturnBoolean)
> > > > If IsNumeric(txtb) Then
> > > > If txtb < 1 Or txtb > 7 Then Cancel = True

> > > > End If
> > > > If Not IsNumeric(txtb) Then Cancel = True
> > > > End Sub

> > > > Regards Ron

Wed, 18 Jun 1902 08:00:00 GMT

 Page 1 of 1 [ 9 post ]

Relevant Pages