Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Page 2 of 2 FirstFirst 12
Results 11 to 19 of 19

Thread: VB Code Needed or Data Forms

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

    Default

    Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)

    Hey Mudface This Line VBA Says It Has Errors On It Please Help


    PS. Here Is All The Code I Have Input


    Private Sub cmdEnterInvoiceData_Click()

    Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)
    Exit Sub

    WrongInput:
    MsgBox "Please Enter A Valid Invoice Number"
    txtInvoiceNum.Text = ""
    txtInvoiceNum.SetFocus






    End Sub

    Private Sub txtInvoiceNum_Change()

    End Sub

    Private Sub UserForm_Click()

    End Sub

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

    Default

    Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)

    Hey Mudface This Line VBA Says It Has Errors On It Please Help


    PS. Here Is All The Code I Have Input


    Private Sub cmdEnterInvoiceData_Click()

    Sheet1.Range("b11").Value = CDbl(txtInvoiceNum.Text)
    Exit Sub

    WrongInput:
    MsgBox "Please Enter A Valid Invoice Number"
    txtInvoiceNum.Text = ""
    txtInvoiceNum.SetFocus






    End Sub

    Private Sub txtInvoiceNum_Change()

    End Sub

    Private Sub UserForm_Click()

    End Sub

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

    Default

    PS that debug error only comes up when I enter words however I want the error message to come up not the VBA debugger

  4. #14
    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

    You've missed out the On Error ... line. The point of that is that it traps the error when you enter non-numeric data, and goes to the error handler called WrongInput. Select the code I posted, copy it ALL and paste it over your existing code.

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

    Default

    Ok This is getting too complicated I will start a new thread

  6. #16
    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

    No, it's quite simple, copy the code below and paste it over your existing code, it works fine for me: -

    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

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

    Default

    thank you very much for helping me it works now sorry for doubting your VB talents

  8. #18
    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

    Heh, you're right to doubt my talents . You just missed a line out, that's all. Good luck with the rest, think you'll get a higher mark than Sami?

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

    Default

    Nah Sami stated the project three months before me and he did all the excel project book I did three chapters and started the project around late february using my own knowledge on ecel and this message board(it's in on friday) and I have done no implementation while Sami has doen about 20 pages

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
  •