Maybe an easy one

viper

Active Member
Joined
Feb 15, 2002
Messages
382
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,
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
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:<pre>

Private Sub CommandButton2_Click()
If cells<> b10 then
msgbox ("Incorrect numbers entered")
exit sub
else
Transfer data
end if
Unload UserForm1
GetAns
End Sub</pre>
_________________<font color = green> Mark O'Brien
This message was edited by Mark O'Brien on 2002-02-21 10:22
 
Upvote 0
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,
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,213,526
Messages
6,114,122
Members
448,550
Latest member
CAT RG

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top