exit sub

Private Sub Macro1()
  If Range("param!A1") = 1 Then
      'exit sub here??
   End If
   
   'bla..................
End Sub

how to exit sub above?
LVL 4
aaaaaaAsked:
Who is Participating?
 
Guy Hengel [angelIII / a3]Connect With a Mentor Billing EngineerCommented:
Private Sub Macro1()
  If Range("param!A1") = 1 Then
      exit sub
   End If
   
   'bla..................
End Sub

or like this:

Private Sub Macro1()
  If Range("param!A1") = 1 Then
      goto done:
   End If
   
   'bla..................

done:
End Sub
0
 
basicinstinctCommented:
Why not just do this:

Private Sub Macro1()
  If Range("param!A1") <> 1 Then
    'bla..................
  End If
End Sub
0
 
aaaaaaAuthor Commented:
can direct exit?

i dun want add extra line "done:"
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
aaaaaaAuthor Commented:
basicinstinct:

 my 'bla....... is very long.
 i dun want confise in (if else)
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
>can direct exit?
yes
0
 
aaaaaaAuthor Commented:
angelIII:

how?
0
 
BrownheadCommented:
-Functions
Code: Exit Function
Example:
'//Code\\
Private Function Test() as String
 Test="1"
 Exit Function
 Test = "2"
End Function
'\\Code//

-Subs
Code: Exit Sub
Example:
'//Code\\
Private Sub Test()
 MsgBox "1"
 Exit Sub
 MsgBox "2"
End Function
'\\Code//

-For Loop
Code: Exit For
Example:
'//Code\\
For A = 1 to 300
If (A=250) then Exit For
Next A
'\\Code//

-Do Loop
Code: Exit Do
Example:
'//Code\\
Do
 If (InputBox("Enter Password")="PWord") Then Exit Do
 MsgBox "Wrong, Try Again"
Loop
'\\Code//

-Property
Code: Exit Property
Example:
'//Code\\
Public Property Get Test() As String
If (mTest = "<VOID>") Then Exit Property
Test = mTest
End Property
'\\Code//
0
 
BrownheadCommented:
For your question, it would be:

Exit Sub

Private Sub Macro1()
  If Range("param!A1") = 1 Then
      Exit Sub
   End If
   
   'bla..................
End Sub
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
I think I DID post that already (in my very first comment)...
correct me if I am wrong...
0
 
aaaaaaAuthor Commented:
angelIII:

sorry, i miss your code:
Private Sub Macro1()
  If Range("param!A1") = 1 Then
      exit sub
   End If
   
   'bla..................
End Sub

this is because the ie scroll down and i not see it just now!
how can i correct it? can i reset the point?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you could, but it's fine for me. just surprised :-)
0
 
aaaaaaAuthor Commented:
is my fault, please teach me how to reset!
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
ok. post a question in the community support topic area, with a link to this question.
a moderator will reopen the question so you can close the question again.

if you want to split points (with at least 30 points for each expert), you have to obviously increase the points of your question to 60, then below the last comment you will see the "split points" link
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.