ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Case Statment in Err trapping (https://www.excelbanter.com/excel-programming/405102-case-statment-err-trapping.html)

lwm

Case Statment in Err trapping
 
I am having trouble with the code in 2:

when I add this code:
ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2

I get an errror:

Case Else outside Select Case

When I remark out the Case Else I get the error:

End Select without Select Case

What is wron g with the code.

The statement that appears to be causing the problem

ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2


Is giving the user a choice of continuing or quiting.

Thank you for your help and hopefully I have provided enough detail.



Badinput:
Select Case Erl
Case Is = 1
Msg = "Error! " & Esp & "You must Enter numbers between " & TabMin & Esp
& TabMax & _
vbCr & vbCr & " rerun Macro"
MsgBox Buttons:=vbCritical, prompt:=Msg

MsgBox "Ending program now"
Application.StatusBar = False
Application.ScreenUpdating = True

Case Is = 2
Msg = "Error! " & Esp & "Dublicate Tab name " & Esp & NewSheet & _
vbCr & vbCr & " Enter a unique Tab name"
' MsgBox prompt:=Msg, Buttons:=vbCritical
ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2

Case Else
Msg = "ending program"
MsgBox Msg
Exit Sub

End Select

Per Jessen[_2_]

Case Statment in Err trapping
 
On 27 Jan., 23:10, lwm wrote:
I am having trouble with the code in 2:

when I add this code:
ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
* * * * * * * * * If ResPonse = vbNo Then
* * * * * * * * * * *Exit Sub

* * * * * * * * * Else
* * * * * * * * * * *GoTo 2

I get an *errror:

Case Else outside Select Case

When I remark out the Case Else I get the error:

End Select without Select Case

What is wron g with the code.

The statement that appears to be causing the problem

*ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
* * * * * * * * * If ResPonse = vbNo Then
* * * * * * * * * * *Exit Sub

* * * * * * * * * Else
* * * * * * * * * * *GoTo 2

Is giving the user a choice of continuing or quiting.

Thank you for your help and hopefully I have provided enough detail.

Badinput:
* Select Case Erl
* * Case Is = 1
* * Msg = "Error! " & Esp & "You must Enter numbers between " & TabMin & Esp
& TabMax & _
* * * * * * * *vbCr & vbCr & " rerun Macro"
* * * * * * * MsgBox Buttons:=vbCritical, prompt:=Msg

* * * * * * * MsgBox "Ending program now"
* * * * * * * Application.StatusBar = False
* * * * * * * Application.ScreenUpdating = True

* * Case Is = 2
* * * Msg = "Error! " & Esp & "Dublicate Tab name " & Esp & NewSheet & _
* * * * * * * *vbCr & vbCr & " Enter a unique Tab name"
* * * * * * * *' MsgBox prompt:=Msg, Buttons:=vbCritical
* * * * * * * ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
* * * * * * * * * If ResPonse = vbNo Then
* * * * * * * * * * *Exit Sub

* * * * * * * * * Else
* * * * * * * * * * *GoTo 2

* Case Else
* * Msg = "ending program"
* * MsgBox Msg
* * * Exit Sub

* * End Select


Hi

You are missing "End If" before "Case Else"

Regards,

Per

lwm

Case Statment in Err trapping
 
My face is red with embracement.

Thank you.

"Per Jessen" wrote:

On 27 Jan., 23:10, lwm wrote:
I am having trouble with the code in 2:

when I add this code:
ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2

I get an errror:

Case Else outside Select Case

When I remark out the Case Else I get the error:

End Select without Select Case

What is wron g with the code.

The statement that appears to be causing the problem

ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2

Is giving the user a choice of continuing or quiting.

Thank you for your help and hopefully I have provided enough detail.

Badinput:
Select Case Erl
Case Is = 1
Msg = "Error! " & Esp & "You must Enter numbers between " & TabMin & Esp
& TabMax & _
vbCr & vbCr & " rerun Macro"
MsgBox Buttons:=vbCritical, prompt:=Msg

MsgBox "Ending program now"
Application.StatusBar = False
Application.ScreenUpdating = True

Case Is = 2
Msg = "Error! " & Esp & "Dublicate Tab name " & Esp & NewSheet & _
vbCr & vbCr & " Enter a unique Tab name"
' MsgBox prompt:=Msg, Buttons:=vbCritical
ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2

Case Else
Msg = "ending program"
MsgBox Msg
Exit Sub

End Select


Hi

You are missing "End If" before "Case Else"

Regards,

Per


James[_43_]

Case Statment in Err trapping
 
Hi lvm,

You need an End If statement immediately after Goto 2.

Cheers

James A.

"lwm" wrote in message
...
I am having trouble with the code in 2:

when I add this code:
ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2

I get an errror:

Case Else outside Select Case

When I remark out the Case Else I get the error:

End Select without Select Case

What is wron g with the code.

The statement that appears to be causing the problem

ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2


Is giving the user a choice of continuing or quiting.

Thank you for your help and hopefully I have provided enough detail.



Badinput:
Select Case Erl
Case Is = 1
Msg = "Error! " & Esp & "You must Enter numbers between " & TabMin &
Esp
& TabMax & _
vbCr & vbCr & " rerun Macro"
MsgBox Buttons:=vbCritical, prompt:=Msg

MsgBox "Ending program now"
Application.StatusBar = False
Application.ScreenUpdating = True

Case Is = 2
Msg = "Error! " & Esp & "Dublicate Tab name " & Esp & NewSheet & _
vbCr & vbCr & " Enter a unique Tab name"
' MsgBox prompt:=Msg, Buttons:=vbCritical
ResPonse = MsgBox(prompt:=Msg, Buttons:=vbYesNo)
If ResPonse = vbNo Then
Exit Sub

Else
GoTo 2

Case Else
Msg = "ending program"
MsgBox Msg
Exit Sub

End Select




All times are GMT +1. The time now is 05:14 PM.

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