Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 2 of 2

Thread: userform question

  1. #1
    Board Regular
    Join Date
    Feb 2002
    Location
    Jefferson City, Missouri
    Posts
    382
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I am using a userform to input accounts and amounts into a ledger. How can I make sure that individual account amounts match the invoice total and if not let the user know so that the user can check the input before the userform posts to the ledger?

    I've tried inserting a separate module and used this code:

    Sub CheckData()
    If Textbox1.Value = Textbox2.Value + Textbox3.Value + Textbox3.Value + Textbox4.Value Then

    Exit Sub

    Else MsgBox ("Please check your input, account s and invoice don't match!")

    End IF

    End Sub

    I called this module before the posting of the information but it didn't work. It posted it anyway not matter if the totals matched or not.

    Thanks,


    I appreciate the help from everyone at Mr. Excel.

    viper

  2. #2
    MrExcel MVP Russell Hauf's Avatar
    Join Date
    Feb 2002
    Location
    Portland, OR Area - USA
    Posts
    1,609
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    I think that having the function check your invoice amounts and then returning a value would be better. Something like this:

    Code:
    Function CheckData() as Boolean
    
    CheckData = (Textbox1.Value = Textbox2.Value + Textbox3.Value + Textbox3.Value + Textbox4.Value) 
    
    End Function
    Exit Sub

    In the procedure where you will be sending the data to the sheet, put something like this:

    If Not CheckData Then
    MsgBox ("Please check your input, account s and invoice don't match!")
    Exit Sub
    End If

    ________________

    Hope this helps,

    Russell

    p.s. - I just noticed that you are adding TextBox3 twice in your example...which I copied for my example.


    [ This Message was edited by: Russell Hauf on 2002-03-28 12:59 ]

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
  •