+ Reply to Thread
Results 1 to 4 of 4

Check if input is a number or text

Hybrid View

soma104 Check if input is a number or... 03-23-2010, 01:15 PM
mdbct Re: Check if input is a... 03-23-2010, 01:21 PM
soma104 Re: Check if input is a... 03-23-2010, 01:24 PM
Marcol Re: Check if input is a... 03-23-2010, 01:32 PM
  1. #1
    Registered User
    Join Date
    11-28-2006
    Posts
    63

    Question Check if input is a number or text

    Hi,

    I have an textbox on an excel form that requires the user to input a number. Is there a statement that I can use in my VBA to check if the value is a number or text prior to applying it to a formula.

    Soma104
    Last edited by soma104; 03-23-2010 at 01:25 PM.

  2. #2
    Valued Forum Contributor mdbct's Avatar
    Join Date
    11-11-2005
    Location
    CT
    MS-Off Ver
    2003 & 2007
    Posts
    848

    Re: Check if input is a number or text

    The IsNumeric function should do the trick
    If IsNumeric(textbox) then
    ....
    Else
    ...
    End If

  3. #3
    Registered User
    Join Date
    11-28-2006
    Posts
    63

    Re: Check if input is a number or text

    Thank you, that's exactly what I needed.

    Soma104

  4. #4
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Check if input is a number or text

    How about not allowing any input in your Textbox, other than numbers?

    Private Sub TextBox1_KeyPress(ByVal KeyAscii As MSForms.ReturnInteger)
        'Allow decimal point
        If KeyAscii = 46 Then
            KeyAscii = KeyAscii
            Exit Sub
        End If
        ' Allow numbers only
        If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
    
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1