Slicemahn
02-10-2022, 10:47 AM
Good day VBAExpress Nation!
I am challenged to find a way to set up a conditional statement for an array. More specifically, I want to test if an item is in the array, if it matches perform a copy operation to a new location, if doesn't match then move to the next file. My code is below:
Sub OpenFolder()Dim FileName As String
Dim fPath As String
Dim fDtName As String
Dim i As Long
Dim j As Long
Dim dbTarget As String
dbRosterFolder = ActiveWorkbook.Sheets("Production Dbs").Range("D1").CurrentRegion.Columns(4).Value
fDtName = Format(Now, "yyyy-mm-dd ")
' Loop through Db Roster locations
For i = 2 To UBound(dbRosterFolder)
' placeholder
Dim dbDirectoryContents() As String
ReDim dbDirectoryContents(1000)
dbTarget = Dir$(Cells(i, 4).Value)
Do While dbTarget <> ""
dbDirectoryContents(Counter) = dbTarget
dbTarget = Dir$
Counter = Counter + 1
Loop
Next i
End Sub
I am challenged to find a way to set up a conditional statement for an array. More specifically, I want to test if an item is in the array, if it matches perform a copy operation to a new location, if doesn't match then move to the next file. My code is below:
Sub OpenFolder()Dim FileName As String
Dim fPath As String
Dim fDtName As String
Dim i As Long
Dim j As Long
Dim dbTarget As String
dbRosterFolder = ActiveWorkbook.Sheets("Production Dbs").Range("D1").CurrentRegion.Columns(4).Value
fDtName = Format(Now, "yyyy-mm-dd ")
' Loop through Db Roster locations
For i = 2 To UBound(dbRosterFolder)
' placeholder
Dim dbDirectoryContents() As String
ReDim dbDirectoryContents(1000)
dbTarget = Dir$(Cells(i, 4).Value)
Do While dbTarget <> ""
dbDirectoryContents(Counter) = dbTarget
dbTarget = Dir$
Counter = Counter + 1
Loop
Next i
End Sub