![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
|
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 | |
|
MrExcel MVP
Join Date: Feb 2002
Location: Columbus, OH, USA
Posts: 3,519
|
Quote:
_________________ Mark O'Brien [ This Message was edited by: Mark O'Brien on 2002-02-21 10:22 ] |
|
|
|
|
|
|
#3 |
|
Board Regular
Join Date: Feb 2002
Location: Jefferson City, Missouri
Posts: 383
|
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 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
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 |
|
Legend
Join Date: Feb 2002
Location: Minneapolis, Mn, USA
Posts: 9,704
|
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 |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|