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

Thread: Maybe an easy one

  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'm having trouble with an error msg.
    At the time of my error it displays the msg I want but then finish out the routine. I can't figure out how to keep it open. I am using this code:
    Private Sub CommandButton2_Click()
    If cells <> b10 then
    msgbox ("Incorrect numbers entered")
    else
    Transfer data
    end if
    Unload UserForm1
    GetAns
    End Sub
    My problem is when the msgbox appears and I click okay the sub continues past the transfer data point and jumps the unload userform1 then getans. I need for the msg box to appear to notify of the error but allow me the chance to correct it, then transfer the data, then unload the userform, then getAns befor exiting the sub. Any ideas?

    Thanks,

  2. #2
    MrExcel MVP Mark O'Brien's Avatar
    Join Date
    Feb 2002
    Location
    Columbus, OH, USA
    Posts
    3,530
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    On 2002-02-21 09:37, viper wrote:
    I'm having trouble with an error msg.
    At the time of my error it displays the msg I want but then finish out the routine. I can't figure out how to keep it open. I am using this code:
    Private Sub CommandButton2_Click()
    If cells <> b10 then
    msgbox ("Incorrect numbers entered")
    else
    Transfer data
    end if
    Unload UserForm1
    GetAns
    End Sub
    My problem is when the msgbox appears and I click okay the sub continues past the transfer data point and jumps the unload userform1 then getans. I need for the msg box to appear to notify of the error but allow me the chance to correct it, then transfer the data, then unload the userform, then getAns befor exiting the sub. Any ideas?

    Thanks,
    Try:



    Private Sub CommandButton2_Click()
    If cells <> b10 then
    msgbox ("Incorrect numbers entered")
    exit sub
    else
    Transfer data
    end if
    Unload UserForm1
    GetAns
    End Sub


    _________________
    Mark O'Brien

    [ This Message was edited by: Mark O'Brien on 2002-02-21 10:22 ]

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

    Default

    Worked great, I had to clear one of cells when the msg appeared(apparently it kept it in memory so when changing the other one to equal the correct one I still got the message) but adding a clear code and it works great now.

    Thank you,

    I appreciate the help from everyone at Mr. Excel.

    viper

  4. #4
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Viper, I read your question a little differently. It sounded to me that you wanted to prompt the user for a correction before killing the "macro." Maybe not, but if so, I whipped up the following three programs (that interface):

    Private Sub CommandButton2_Click()
    Application.Run ("verify")
    If Cells = b10 Then
    Application.Run ("loadit")
    End If
    End Sub

    Private Sub verify()
    myval = Cells
    If Cells <> b10 Then
    f = Application.InputBox(prompt:="Incorrect numbers entered, please enter correct numbers", Title:="Not So Fast", Type:=1)
    If f <> False Then
    Cells = f
    If Cells <> b10 Then
    Application.Run ("verify")
    End If
    Else:
    MsgBox ("task aborted")
    End If
    End If
    End Sub

    Private Sub loadit()
    Transfer data
    Unload UserForm1
    GetAns
    End Sub

    Very memory exhaustive stuff. Either way, Cheers!

    NateO

    [ This Message was edited by: NateO on 2002-02-21 11:44 ]

  5. #5
    Legend NateO's Avatar
    Join Date
    Feb 2002
    Location
    Minneapolis, Mn, USA
    Posts
    9,700
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    What may be even better (places b10 in the input box as a default):

    f = Application.InputBox(prompt:="Incorrect numbers entered, please enter correct numbers", default:=b10, Title:="Not So Fast", Type:=1)

    Cheers,

    Nate

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
  •