User form - Testing for numbers or text

N

NDBC

I need the following if statement to be true for times when the the text box
Rider5.Text is numbers less than 100 (done), or any text value, or blank. I
can put in the or statements but don't know what function to use.

'When rider number is less than lowest rider number or Any text value
(entered in error)
If Rider5.Text < 100 Then
UnkRow = Sheets("Unknown").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Unknown").Range("A" & UnkRow) = Rider5.Text
Sheets("Unknown").Range("B" & UnkRow) = Time5.Text

Thanks
 
J

Jacob Skaria

Two options..

If you dont have any code to be executed after the one you pasted below try

If IsNumeric(Rider5.Text) = True Then
If Rider5.Text > 99 Then Exit Sub
End If
'The below codes will be executed only if text or value less than 100
UnkRow = Sheets("Unknown").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Unknown").Range("A" & UnkRow) = Rider5.Text
Sheets("Unknown").Range("B" & UnkRow) = Time5.Text
End Sub
'-------------------------------------------------------------------------
Another approach is to have a boolean to validate and

Dim blnPass As Boolean
If IsNumeric(Rider5.Text) = False Then
blnPass = True
Else
If Rider5.Text < 100 Then blnPass = True
End If

If blnPass = True Then
UnkRow = Sheets("Unknown").Cells(Rows.Count, "A").End(xlUp).Row + 1
Sheets("Unknown").Range("A" & UnkRow) = Rider5.Text
Sheets("Unknown").Range("B" & UnkRow) = Time5.Text
End If

'Continue with the rest of your code

End Sub

If this post helps click Yes
 
J

Jacob Skaria

You can ignore the previous post and try

If Rider5.Value < 100 Or Trim(Rider5.Text) = "" Or IsNumeric(Rider5.Text) =
False Then

'your code

End If

If this post helps click Yes
 
N

NDBC

Jacob, I put in the code below and it still fails for both text and blank. Is
there something that could be wrong in the way I have the text box properties
set up. I have even tried setting default value of box to "blank" and if
rider5.text ="blank" then, just to see if I could work with text and it
failed too. Only seems to want to work with numbers for some reason.

Thanks
 
N

NDBC

My apologies Jacob. I just changed the rider5.text <100 to rider5.value<100
and everything works fine now.

You were on the money yet again
 
N

NDBC

Or IsNumeric(Rider5.Text) = False Then

This statement alone handles blank cells too.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top