sanilmathews
Board Regular
- Joined
- Jun 28, 2011
- Messages
- 102
I have the below code which renames the files saved in path listed in column A with the names listed in column B (with file extension). The code is working fine.
However, I would like to have a provision in the same code that, if any of the cells in column A and B are empty then the code should skip to next non-empty cell in columns A and Column B.
<!--[if !supportLineBreakNewLine]-->
<!--[endif]-->
However, I would like to have a provision in the same code that, if any of the cells in column A and B are empty then the code should skip to next non-empty cell in columns A and Column B.
<!--[if !supportLineBreakNewLine]-->
Code:
Sub Rename()
'Tools->Reference->Microsoft Scripting Runtime
Dim fso As New FileSystemObject
Dim fl As File
Dim r As Long
Worksheets("Sheet1").Select
For r = 1 To 45
Set fl = fso.GetFile(Cells(r + 1, "A")) 'Paths
fl.Name = Cells(r + 1, "B") 'New File Name
On Error GoTo Errorhandler
Next
Errorhandler: Exit Sub
End Sub