ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   How do I exit from a macro when a condition is not met (https://www.excelbanter.com/excel-programming/410621-how-do-i-exit-macro-when-condition-not-met.html)

Y2D3Y4

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



Gary Keramidas

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





Madiya

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

Y2D3Y4

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







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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com