?
Solved

exit sub

Posted on 2006-05-23
14
Medium Priority
?
461 Views
Last Modified: 2010-05-01
Private Sub Macro1()
  If Range("param!A1") = 1 Then
      'exit sub here??
   End If
   
   'bla..................
End Sub

how to exit sub above?
0
Comment
Question by:aaaaaa
  • 5
  • 5
  • 2
  • +1
13 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 200 total points
ID: 16740710
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
 
LVL 23

Expert Comment

by:basicinstinct
ID: 16740725
Why not just do this:

Private Sub Macro1()
  If Range("param!A1") <> 1 Then
    'bla..................
  End If
End Sub
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 16740727
can direct exit?

i dun want add extra line "done:"
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:aaaaaa
ID: 16740732
basicinstinct:

 my 'bla....... is very long.
 i dun want confise in (if else)
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16740742
>can direct exit?
yes
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 16740767
angelIII:

how?
0
 
LVL 1

Expert Comment

by:Brownhead
ID: 16740772
-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
 
LVL 1

Expert Comment

by:Brownhead
ID: 16740774
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16740796
I think I DID post that already (in my very first comment)...
correct me if I am wrong...
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 16740837
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
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16740859
you could, but it's fine for me. just surprised :-)
0
 
LVL 4

Author Comment

by:aaaaaa
ID: 16740864
is my fault, please teach me how to reset!
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 16740908
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

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question