Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do I exit from a macro when a condition is not met

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default How do I exit from a macro when a condition is not met

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" wrote in message
...
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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 239
Default How do I exit from a macro when a condition is not met

On May 8, 9:20*am, Y2D3Y4 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default How do I exit from a macro when a condition is not met

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Run macro on exit Steve Excel Discussion (Misc queries) 12 October 25th 09 01:43 PM
UserForm_Initialize, how to exit sub based on condition? Rick S. Excel Programming 4 November 21st 07 02:12 PM
Exit via macro only? Brisbane Rob Excel Discussion (Misc queries) 1 October 13th 05 01:16 PM
on exit macro ditchy Excel Discussion (Misc queries) 2 May 3rd 05 12:11 AM
Exit a macro from an error condition ChuckM[_2_] Excel Programming 2 January 19th 04 02:12 PM


All times are GMT +1. The time now is 03:04 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"