I have come to many scenarios where I want to loop through an array until a certain criteria is met.
I tried messing around with the do until command but could not get it to work.
so what I am wanting to do is loop though and array (which has file locations listed) but stop once it finds a file that exists.
the code I have works since it will never have the same file in the location but would like to know how to get something like this to work for other areas.
below is the code I am using but but would really like to figure out how to stop the Next i loop once a criteria is met. (I know it is probably easy but I have self taught myself VBA so thanks for your help)
I tried messing around with the do until command but could not get it to work.
so what I am wanting to do is loop though and array (which has file locations listed) but stop once it finds a file that exists.
the code I have works since it will never have the same file in the location but would like to know how to get something like this to work for other areas.
below is the code I am using but but would really like to figure out how to stop the Next i loop once a criteria is met. (I know it is probably easy but I have self taught myself VBA so thanks for your help)
VBA Code:
Dim strFileName(1 To 19) As String
Dim strFileExists As String
Dim i As Integer
strFileName(1) = "..."
strFileName(2) = "..."
strFileName(3) = "..."
strFileName(4) = "..."
strFileName(5) = "..."
strFileName(6) = "..."
strFileName(7) = "..."
strFileName(8) = "..."
strFileName(9) = "...."
strFileName(10) = "..."
strFileName(11) = "..."
strFileName(12) = "...."
strFileName(13) = "..."
strFileName(14) = "...."
strFileName(15) = "..."
strFileName(16) = "..."
strFileName(17) = "..."
strFileName(18) = "..."
strFileName(19) = "..."
For i = 1 To 19
strFileExists = Dir(strFileName(0 + i))
If Not strFileExists = "" Then
dbpath = strFileName(0 + i)
End If
Next i
End Function