PC Review


Reply
Thread Tools Rate Thread

How do I exit from a macro when a condition is not met

 
 
Y2D3Y4
Guest
Posts: n/a
 
      8th May 2008
In Excel 2003 I have a macro that checks if a cell is not zero.

Range ("P124").Select
If Selection.Value <> 0 Then
Call Check
End If

Sub Check()
Dim Msg, Style, Title, Response
Msg = "This JV does not balance, please correct it before you continue."
Style = vbOKCancel
Title = "Out of Balance
Response = MsgBox (Msg, Style, Title)
End Sub

I want to exit out of the macro routines when the user presses OK.

Thanks

Andy


 
Reply With Quote
 
 
 
 
Gary Keramidas
Guest
Posts: n/a
 
      8th May 2008
looks like it already exits, but maybe this will help

Sub Check()
Dim Msg, Style, Title, Response
Msg = "This JV does not balance, please correct it before you continue."
Style = vbOKCancel
Title = "Out of Balance"
Response = MsgBox(Msg, Style, Title)
If Response = 1 Then ' ok pressed
Exit Sub
Else
'response = 2
' do something else
End If
End Sub




--


Gary


"Y2D3Y4" <(E-Mail Removed)> wrote in message
news:F24BEA99-0FEF-4A2E-910E-(E-Mail Removed)...
> In Excel 2003 I have a macro that checks if a cell is not zero.
>
> Range ("P124").Select
> If Selection.Value <> 0 Then
> Call Check
> End If
>
> Sub Check()
> Dim Msg, Style, Title, Response
> Msg = "This JV does not balance, please correct it before you continue."
> Style = vbOKCancel
> Title = "Out of Balance
> Response = MsgBox (Msg, Style, Title)
> End Sub
>
> I want to exit out of the macro routines when the user presses OK.
>
> Thanks
>
> Andy
>
>



 
Reply With Quote
 
Madiya
Guest
Posts: n/a
 
      8th May 2008
On May 8, 9:20*am, Y2D3Y4 <Y2D...@discussions.microsoft.com> wrote:
> In Excel 2003 I have a macro that checks if a cell is not zero.
>
> Range ("P124").Select
> If Selection.Value <> 0 Then
> Call Check
> End If
>
> Sub Check()
> Dim Msg, Style, Title, Response
> Msg = "This JV does not balance, please correct it before you continue."
> Style = vbOKCancel
> Title = "Out of Balance
> Response = MsgBox (Msg, Style, Title)
> End Sub
>
> I want to exit out of the macro routines when the user presses OK.
>
> Thanks
>
> Andy


Sub Check()
Dim Msg, Style, Title, Response
Msg = "This JV does not balance, please correct it before you
continue."
Style = vbOKCancel
Title = "Out of Balance "
Response = MsgBox(Msg, Style, Title)
If Response = vbOK Then
Exit Sub
End If
End Sub

Regards,
Madiya
 
Reply With Quote
 
y2d3y4
Guest
Posts: n/a
 
      9th May 2008
Thank you,
This works. I did have to re-arrange the subs, but this works great.

"Gary Keramidas" wrote:

> looks like it already exits, but maybe this will help
>
> Sub Check()
> Dim Msg, Style, Title, Response
> Msg = "This JV does not balance, please correct it before you continue."
> Style = vbOKCancel
> Title = "Out of Balance"
> Response = MsgBox(Msg, Style, Title)
> If Response = 1 Then ' ok pressed
> Exit Sub
> Else
> 'response = 2
> ' do something else
> End If
> End Sub
>
>
>
>
> --
>
>
> Gary
>
>
> "Y2D3Y4" <(E-Mail Removed)> wrote in message
> news:F24BEA99-0FEF-4A2E-910E-(E-Mail Removed)...
> > In Excel 2003 I have a macro that checks if a cell is not zero.
> >
> > Range ("P124").Select
> > If Selection.Value <> 0 Then
> > Call Check
> > End If
> >
> > Sub Check()
> > Dim Msg, Style, Title, Response
> > Msg = "This JV does not balance, please correct it before you continue."
> > Style = vbOKCancel
> > Title = "Out of Balance
> > Response = MsgBox (Msg, Style, Title)
> > End Sub
> >
> > I want to exit out of the macro routines when the user presses OK.
> >
> > Thanks
> >
> > Andy
> >
> >

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
exit a form if condition not true Jean-Paul Microsoft Access Form Coding 1 5th Jan 2009 12:24 PM
UserForm_Initialize, how to exit sub based on condition? =?Utf-8?B?UmljayBTLg==?= Microsoft Excel Programming 5 21st Nov 2007 05:41 PM
exit macro from VB ?? steve Microsoft Access 2 3rd Jan 2007 06:08 PM
Exit via macro only? Brisbane Rob Microsoft Excel Misc 1 13th Oct 2005 01:16 PM
Exit a macro from an error condition ChuckM Microsoft Excel Programming 2 19th Jan 2004 02:12 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:00 AM.