Sub RenameFiles()
Dim lngRow As Long, lngRowCount As Long, lngStartRow As Long
Dim f As String, strPath As String, newPath As String
On Error Resume Next
strPath = "C:\Pictures\"
lngRowCount = Cells(65536, "C").End(xlUp).Row
lngStartRow = 1
Application.ScreenUpdating = False
For lngRow = lngStartRow To lngRowCount
If (Cells(lngRow, "C") <> "") And (Cells(lngRow, "K") <> "") And (Cells(lngRow, "I") <> "") Then
newPath = "C:\Pictures\" & Cells(lngRow, "I") 'Homeroom folder
f = Dir(newPath, 16) 'Returns a blank if folder is missing
If f = "" Then MkDir newPath 'If homeroom folder is missing, must create one before moving file
Name strPath & Cells(lngRow, "C") As newPath & "\" & Cells(lngRow, "K") 'Move the file
Cells(lngRow, "L") = "Renamed"
End If
Next
Application.ScreenUpdating = True
End Sub
|