Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: VB Code Needed or Data Forms

  1. #1
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi,

    I've Made A Data Form Using Visual Basic And I've made An Input Where You Type Something And It Goes To The Requested Cell, However I Would Like It To Be Data That Is Valid So When Someone Types In The (For Example) Invoice Number 'S' A Pop Up Menu Will Say Please Enter A Number So I'd Like The Data Input Into The Box Only Data If It Helps Here IS The Code I've Started With:

    Private Sub cmdEnterInvoiceData_Click()
    Sheet1.Range("b11").Value = txtInvoiceNum

    End Sub

    Private Sub UserForm_Click()

    End Sub

  2. #2
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try the following code:

    If Application.WorksheetFunction.IsNumber(txtInvoiceNum) = False Then MsgBox "Enter in a valid number"
    Else: Sheet1.Range("b11").Value = txtInvoiceNum
    End If

    The code tests whether or not txtInvoiceNum is a number or not.
    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  3. #3
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Al Chara Thank You Very Much For Your Help However There Is A Problem (For Help Here Is The Code)

    Private Sub cmdEnterInvoiceData_Click()
    If Application.WorksheetFunction.IsNumber(txtInvoiceNum) = False Then MsgBox "Enter in a valid number"
    Else: Sheet1.Range("b11").Value = txtInvoiceNum
    End If


    End Sub

    Private Sub UserForm_Click()

    End Sub


    When I click something it says I have to debug it and in THe VB editor When I Scroll Through It Displays This Error Message:

    Compile Error:

    Else Without If

    Can You Give Me A Bit More Guidance Muchos Gracias

  4. #4
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Anyone This Should Be Easy

  5. #5
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try the following code:

    If Application.WorksheetFunction.IsNumber(txtInvoiceNum) = False Then
    MsgBox "Enter in a valid number"
    Else: Sheet1.Range("b11").Value = txtInvoiceNum
    End If

    To be careful make sure [MsgBox "Enter in a valid number"] is indented.

    Best regards,
    Allan Chara
    http://www.mrspreadsheets.com

  6. #6
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi It Does Help One More Question How Do I Indent It?

  7. #7
    MrExcel MVP Al Chara's Avatar
    Join Date
    Feb 2002
    Location
    Newark, Delaware
    Posts
    1,701
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hit the tab button

  8. #8
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Sorry I Suck At VB

  9. #9
    Board Regular
    Join Date
    Mar 2002
    Posts
    85
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Last Problem But Even When I Type In A Number It Still Says Please Enter A Valid Number

  10. #10
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Sunny, spring-like Hull
    Posts
    3,339
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try the following: -

    Private Sub cmdEnterInvoiceData_Click()

    On Error GoTo WrongInput
    Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)
    Exit Sub

    WrongInput:
    MsgBox "Please enter a number"
    txtInvoiceNum.Text = ""
    txtInvoiceNum.SetFocus

    End Sub

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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