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

  • Thread starter Thread starter Y2D3Y4
  • Start date Start date
Y

Y2D3Y4

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
 
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
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top