+ Reply to Thread
Results 1 to 5 of 5

Elseif Not IsNumber error

  1. #1
    Registered User
    Join Date
    02-15-2006
    Posts
    93

    Elseif Not IsNumber error

    Good evening,

    Having a little trouble with some code. I guess it won't work as I have it but I was wondering if anyone could recommend an easy way to do it. I don't want to write the code to verify each textbox separately. I was hoping to have it do a loop. Here is the code... It is the "Else if..." statement that generates the error. Thanks in advance for any help! dw

    Sub test()
    For i = 1 To 12
    If Updateform.Controls("Textbox" & i).Value = "" Then
    MsgBox ("You have to enter a value in each box.")
    Exit Sub
    ElseIf Not IsNumber(Updateform.Controls("Textbox" & i).Value ) Then
    MsgBox ("Values entered have to be numeric.")
    Exit Sub
    End If
    Next i
    End Sub

  2. #2
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,525
    Hi there,
    Is this in a userform???

    I don't see it happening, but maybe somebody else will,
    I usually use an exit sub for something like this, but lets see if somebody else has an idea

  3. #3
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591
    HI

    The result from a textbox will be text, so the test not isnumber will always be true.

    If the number will always be > 0, then you could convert the text to a numbrer (val) and if it is > 0, then it would be numeric.


    HTH

    rylo

  4. #4
    Registered User
    Join Date
    02-15-2006
    Posts
    93
    To answer the first question, yes the textboxes are on a userform. There are 12 of them and this code is to ensure that all of the required information is provided before it is posted to the sheets.

    As to the second response, I don't think this is the problem. I could be wrong. I am still playing with it but it seems that if I don't use the "controls" feature, the elseif statement works. i.e.


    Sub test()
    If Updateform.Textbox1.Value = "" Then
    MsgBox ("You have to enter a value in each box.")
    Exit Sub
    ElseIf Not IsNumber(Updateform.Textbox1.Value) Then
    MsgBox ("Values entered have to be numeric.")
    Exit Sub
    End If
    End Sub

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I would place this in a Input button on the Form

    Please Login or Register  to view this content.
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

+ 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