Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 01-28-2013, 10:36 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline How to a For loop in VBA Windows XP How to a For loop in VBA Office 2007
Competent Performer
How to a For loop in VBA
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default How to a For loop in VBA

In Visual Basic, the Continue statement will complete the current iteration of a loop and start the next, if any.

Code:
For i = 1 to 10
   ...do some work
   If [some condition] then Continue For
   ...do the rest of the work
Next i
In VBA, the Continue statement gets flagged as invalid.



What's the proper way to end just the current iteration of a For loop in VBA without exiting the loop entirely (Exit Loop)?

Is this different for VBA under Word vs under Excel?

Last edited by Jennifer Murphy; 01-28-2013 at 11:02 PM. Reason: Fixed typo (End For)
Reply With Quote
  #2  
Old 01-29-2013, 03:30 AM
OTPM OTPM is offline How to a For loop in VBA Windows 7 32bit How to a For loop in VBA Office 2010 32bit
Expert
 
Join Date: Apr 2011
Location: West Midlands
Posts: 981
OTPM is on a distinguished road
Default

Hi
Try:

For i = 1 to 10
...do some work
If [some condition] then
...do the rest of the work
Else
Next i

Good luck.
Tony
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to a For loop in VBA Macro to loop in Word Yamaha Rider Word VBA 2 02-07-2012 05:33 PM
How to use for loop in formula in VBA? tinfanide Excel Programming 1 12-06-2011 08:33 AM
While loop not working right Cbrehm Excel Programming 0 05-11-2011 11:05 AM
How to a For loop in VBA Continuous Loop cksm4 Word 6 01-06-2011 09:03 PM
Outlook 2003 restart in a loop Stegel Outlook 0 06-29-2007 12:34 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 10:50 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft