I need to move over 1000 files in various subfolders of root folder at C:\FolderA, to another folder, C:\FolderB. I have the names of the files that I need to move in column B of a sheet. I need the macro to loop through the subfolders of Folder A and refer to the file names in column B. If it finds a match, write, "On hand" in column C and move the file into Folder B. If it doesn't find a match, write, "Does not exist" in column C and do nothing. I drafted my idea of what the code might look like, but I'm getting a "Next without For" error.
Dim objFSO As Object 'FileSystemObject
Dim objFile As Object 'File
Dim objFolder As Object 'Folder
bContinue = True
iRow = 2
Const strFolder As String = "U:\TestFrom"
Const strNewFolder As String = "U:\TestTo"
Set objFSO = CreateObject("Scripting.FileSystemObject")
For Each objFolder In objFSO.GetFolder(strFolder & "\").SubFolders
'If Right(objFolder.Name, 5) = "Test" Then
For Each objFile In objFolder.Files
If Len(Range("B" & CStr(iRow)).Value) = 0 Then ' DO NOTHING IF THE COLUMN IS BLANK
MsgBox "Process executed" ' DONE.
bContinue = False
'CHECK IF FILES EXIST.
If Len(Range(strFolder & "B" & CStr(iRow)).Value) = o Then
Range("C" & CStr(iRow)).Value = "Does not exist"
Range("C" & CStr(iRow)).Font.Bold = True
Range("C" & CStr(iRow)).Value = "On hand"
Range("C" & CStr(iRow)).Font.Bold = False
''If InStr(1, objFile.Name, "dir", vbTextCompare) Then
On Error Resume Next
Kill strNewFolder & "\" & objFile.Name
Err.Clear: On Error GoTo 0
Name objFile.Path As strNewFolder & "\" & objFile.Name
iRow = iRow + 1 ' INCREMENT ROW COUNTER.