Terminating program in VBA

yangf

New Member
Joined
May 27, 2013
Messages
21
Hi All,

I am trying to write a program that prompts the user to enter a number to look up in an excel sheet, and if the user enters incrrectly or if the number is not found, program returns an error message and then terminates...

Is there such syntax that terminates athe program?
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
The End statement terminates execution. Example from VBA Help:

Rich (BB code):
Sub Form_Load()
    Dim Password, Pword
    Password = "Swordfish"
    Pword = InputBox("Type in your password")
    If Pword <> Password Then
        MsgBox "Sorry, incorrect password"
        End
    End If
End Sub
 
Upvote 0
That makes sense but trying it out I realised that it only terminates the sub that it was in, but carries on with the ones following it since another sub calls this sub...
parts of my code:
Code:
Sub StatusReport()

    Dim strProjectNumber As String, LocationAllItems As Long, LocationProcurement As Long
   
    Call NewSheet
    Call FindProject(strProjectNumber, LocationAllItems, LocationProcurement)
    Call TitleBlock(strProjectNumber, LocationAllItems, LocationProcurement)
    Call ViewSetup
   
End Sub

and the if statement is inside the "FindProject" sub:
Code:
Sub FindProject(strProjectNumber, LocationAllItems, LocationProcurement)
        strProjectNumber = InputBox(Prompt:="Please Enter Project Number", _
          Title:="Project Number", Default:="Project Number")

        If strProjectNumber = "Project Number" Or _
           strProjectNumber = vbNullString Then
           MsgBox "Project format not recognized, please try again."
            Exit Sub
           
        Else:
        more code
    
        End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,221,002
Messages
6,157,312
Members
451,414
Latest member
AnhNguyen

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top