Looping Help

Rip181

New Member
Joined
Mar 8, 2021
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
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)

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
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Thank you I knew it had to be something super easy
 
Upvote 0

Forum statistics

Threads
1,214,857
Messages
6,121,948
Members
449,056
Latest member
FreeCricketId

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top