By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,778 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,778 IT Pros & Developers. It's quick & easy.

stop a procedure

100+
P: 142
In excel VBA.
For example,
Expand|Select|Wrap|Line Numbers
  1. If cells(i,1)=1 Then
  2.   Call Procedure1
  3.   Call Procedure2
  4. End If
  5. If ....
  6.   ...
  7. End If
  8. Loop
The Procedure1 and 2 will execute every loop, but I only want the Procedure1 excutes once, and the procedure2 excutes everyloop. How can I do that?
thanks
Apr 30 '07 #1
Share this Question
Share on Google+
4 Replies


Expert 5K+
P: 8,434
Probably the simplest way is to create a variable which you use to "flag" the fact procedure 1 has been run. Each time 'round the loop, if the flag hasn't been set, then run procedure 1 and set the flag.
Apr 30 '07 #2

100+
P: 142
Probably the simplest way is to create a variable which you use to "flag" the fact procedure 1 has been run. Each time 'round the loop, if the flag hasn't been set, then run procedure 1 and set the flag.
what is flag? I try to figure out "Flag" a long time ago, but still can't.
May 1 '07 #3

Expert 5K+
P: 8,434
what is flag? I try to figure out "Flag" a long time ago, but still can't.
The term "flag" just refers to a variable that you use to indicate a particular situation. In this case, a boolean variable that you would set to True to indicate that you have performed the thing you only want to do once.

Here's some pseudo-code showing a general example (based on your situation) of the way a flag might be used...
Expand|Select|Wrap|Line Numbers
  1. Clear flag (set to False)
  2. Start loop
  3.   If Flag is not set Then
  4.     Do Proc1
  5.     Set flag (set value to True)
  6.   End If
  7.   Do Proc2
  8. End Loop
May 1 '07 #4

100+
P: 142
The term "flag" just refers to a variable that you use to indicate a particular situation. In this case, a boolean variable that you would set to True to indicate that you have performed the thing you only want to do once.

Here's some pseudo-code showing a general example (based on your situation) of the way a flag might be used...
Expand|Select|Wrap|Line Numbers
  1. Clear flag (set to False)
  2. Start loop
  3.   If Flag is not set Then
  4.     Do Proc1
  5.     Set flag (set value to True)
  6.   End If
  7.   Do Proc2
  8. End Loop
great, thanks
May 1 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.