Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old February 2nd, 2005, 04:16 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default For....Loop

Hi -

I need to process every entry in an array. So I use the for...loop to do so. And inside the for..loop, I have several steps to process for each entry. However, if any of steps fails, I don't want to continue processing the rest of steps for that particular entry. But I want to go on and process next entry in the array with all the steps in the for...loop. How do I go about skipping rest of steps and go to the next entry? I read somewhere about having a label at the beginning of the statement where I can break out. But can't find it. Any solution is greatly appreciated.

Thanks.
Kathy
Reply With Quote
  #2 (permalink)  
Old February 3rd, 2005, 01:15 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: Chennai, Tamil nadu, India.
Posts: 307
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Vadivel Send a message via Yahoo to Vadivel
Default

How about setting a boolean flag to false when some condition fails. Check this boolean flag before continuing with your other steps / process .. if its true don't process it.

0. Flag = true
1. For Loop
2. You Condition Fails --- so Flag = false
3. If Flag <> false Then
4. Rest of the processing comes here
5. If loop ends here
6. For loop ends here

Best Regards
Vadivel

MVP ASP/ASP.NET
http://vadivel.thinkingms.com
Reply With Quote
  #3 (permalink)  
Old February 3rd, 2005, 02:24 AM
Friend of Wrox
 
Join Date: Oct 2003
Location: , , Finland.
Posts: 168
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Set the counter to the maximun value if the step fails

-vemaju

Reply With Quote
  #4 (permalink)  
Old February 3rd, 2005, 07:37 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Bournemouth, Dorset, United Kingdom.
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

for myloop = 1 to 10 step 1
'processes go here...

if myprocess = false then goto endloop else continue...

EndLoop:
next

Using a label just before the cloisure of the next/loop functionality will allow you to conduct the tests and if a false result is the outcome you point to the EndLoop: label thus skipping any unwanted code.

Cheers
Matthew

Reply With Quote
  #5 (permalink)  
Old February 9th, 2005, 03:29 PM
Authorized User
 
Join Date: Sep 2004
Location: , , .
Posts: 18
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Matthew -

This works! Thank you.

Kathy


Quote:
quote:Originally posted by mjppaba
 for myloop = 1 to 10 step 1
'processes go here...

if myprocess = false then goto endloop else continue...

EndLoop:
next

Using a label just before the cloisure of the next/loop functionality will allow you to conduct the tests and if a false result is the outcome you point to the EndLoop: label thus skipping any unwanted code.

Cheers
Matthew

Reply With Quote
  #6 (permalink)  
Old February 10th, 2005, 06:43 AM
Friend of Wrox
 
Join Date: Jan 2005
Location: Bournemouth, Dorset, United Kingdom.
Posts: 180
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Kathy,

Your more than welcome.

M

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Do Loop stealthdevil Access VBA 5 October 5th, 2006 01:22 PM
Help with for-each loop athanatos XSLT 0 April 10th, 2006 07:20 PM
Do Until loop with IF crmpicco Classic ASP Databases 2 June 15th, 2005 05:35 PM
Do Loop junemo Beginning PHP 8 July 28th, 2004 02:58 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM



All times are GMT -4. The time now is 11:47 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.