Allowing Numeric Entries only...

JST013

Board Regular
Joined
Mar 11, 2015
Messages
74
So I have seen the only numbers method and was trying to use it when I stumbled accidentally upon another way of going about it...

for those who don't know what I'm talking about...the onlynumbers is something like...
Code:
[B]Private Sub OnlyNumbers()[/B]    

If TypeName(Me.ActiveControl) = "TextBox" Then

        With Me.ActiveControl

            If Not IsNumeric(.Value) And .Value <> vbNullString Then

                MsgBox "Sorry, only numbers allowed"

                .Value = vbNullString

            End If

        End With

    End If
[B]End Sub 
[/B]

what worked for me was much more simple. All I did was use an if statement to see if the textbox had a number greater than 60 and any letter is coming up as true...

Granted, in my application the user is entering minutes of an hour, so there entry will never be greater than 60.


it looks like...

Code:
If Me.tbStartMM > 60 Then
        MsgBox ("Invalid Entry.")
End If

I'm basically looking for an answer as to why this works and what situations it wouldn't work in...
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,221,418
Messages
6,159,791
Members
451,589
Latest member
Harold14

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top