Hello, I have a formula that renames files named in column A, for column B, in a given folder. I'm trying to modify this formula, so that instead of using rename, it just duplicates files (filecopy) that are in column A, by the number of times that are in column B, on the same line. I would also like to keep the default folder for the source files, like the VBA rename I made available.
Also, if the number contained in column B is 0 or less, do nothing to avoid errors (unless VBA automatically recognizes that if it is 0 or less, it shouldn't do any duplication or delete anything).
Also, if the number contained in column B is 0 or less, do nothing to avoid errors (unless VBA automatically recognizes that if it is 0 or less, it shouldn't do any duplication or delete anything).
VBA Code:
Sub DuplicateFile()
Dim xDir As String, xFile As String
Dim xRow As Long
Dim ps As String
xDir = "C:\Users\abc"
xFile = Dir(xDir & Application.PathSeparator & "*")
ps = Application.PathSeparator
Do Until xFile = ""
xRow = 0
On Error Resume Next
xRow = Application.Match(xFile, Range("A:A"), 0)
If xRow > 0 Then
Name xDir & ps & xFile As xDir & ps & Cells(xRow, "B").Value
End If
xFile = Dir
Loop
End Sub