LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 16
Default Dynamic change of limits in for...next loop

I have a for...next loop that performs certain actions of a list of
files. These file names are the same except for a numeric identifier
(i.e testfile1.txt, testfile2.txt, testfile4.txt). Occasionally the
file numeric identifiers are not contiguous (see example). I have put
an error trap to deal with the missing file. However, since the
number of files is known (and fixed) when I skip a file number that
does not exist, that means one iteration of the for...next loop has
happened and therefore one less file of the total will be processed.
So if there are 50 files and iterations = 50, then if the file numbers
go to, say, 60, then the files numbered 51-60 will not be processed.

I tried the following code to increment the for...next limits
dynamically but it doesn't work. The limits remain the same. This is
true if I try to adjust either the lower or upper limit. Any ideas?

With Application.FileSearch
.LookIn = FullName
.SearchSubFolders = False
.FileName = "*.txt"
.MatchTextExactly = False
.Execute
Iterations = .FoundFiles.Count
End With

For Index = 1 To Iterations

On Error Resume Next
Documents.Open FileName:=FullName & ShortName & Index & ".txt",
Visible:=True
If Err.Number < 0 Then
Iterations = Iterations + 1
GoTo ReturnIt
End If

...do stuff to opened file

ReturnIt:

Next Index

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
change increasment in a for loop Jared Excel Discussion (Misc queries) 3 October 6th 06 05:54 AM
Loop with dynamic range mthomas[_19_] Excel Programming 7 November 21st 05 08:12 PM
Change the FOR loop top DavidE Excel Programming 3 July 25th 05 08:10 AM
Dynamic execution of a loop Jeroen Kluytmans Excel Programming 1 February 23rd 04 04:09 PM
Using UsedRange as limits in a For Each loop but for cells on another sheet ? tur13o Excel Programming 2 October 23rd 03 01:18 PM


All times are GMT +1. The time now is 06:03 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"