Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / April 2007

Tip: Looking for answers? Try searching our database.

Do loops and omit a couple of iterations?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
andreas - 12 Feb 2007 18:16 GMT
I wonder whether it is possible to iterate through a collection of
objects and omit a couple of iterations, such as

Dim i as integer
For i = 1 to 7 Skip 3,4

Set tbl = ActiveDocument.Tables(i)

If tbl.Rows(1) etc. then
do stuff

End If

Next i

Is this possible, ie. skip the third and fourth table ? `

Help is appreciated. Thank you very much in advance.

Regards,

Andreas
Greg Maxey - 12 Feb 2007 18:29 GMT
> I wonder whether it is possible to iterate through a collection of
> objects and omit a couple of iterations, such as
[quoted text clipped - 18 lines]
>
> Andreas

Yes it is possible:
Sub ScratchMacro()
Dim i As Long
For i = 1 To 7
 Select Case i
   Case Is = 1, 2, 5, 6, 7
     MsgBox "Bob's your uncle"
     'Do Nothing
 End Select
Next i
End Sub
Jay Freedman - 12 Feb 2007 18:32 GMT
It's possible, but not with that kind of syntax. There's a Step option in
the For syntax, but that affects every iteration. Instead, place the
contents of the loop in an If...Then clause like this:

Dim i as integer
For i = 1 to 7
If (i <> 3) And (i <> 4) Then
  Set tbl = ActiveDocument.Tables(i)

  If tbl.Rows(1) etc. then
     'do stuff
  End If
End If
Next i

Another possibility, when you have more than just a few items to skip over,
is to use a Select Case clause.

Signature

Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

> I wonder whether it is possible to iterate through a collection of
> objects and omit a couple of iterations, such as
[quoted text clipped - 18 lines]
>
> Andreas
andreas - 07 Apr 2007 06:08 GMT
> It's possible, but not with that kind of syntax. There's a Step option in
> the For syntax, but that affects every iteration. Instead, place the
[quoted text clipped - 45 lines]
>
> - Zitierten Text anzeigen -

Jay,

I inadvertently forgot to say thank you for your valuable help. It is
working fine. Thank you!
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.