Hi all,
I have created a macro which counts if specific folder "CopyFrom" contains files begining with the name specified in column "B".
Formula takes number of rows to run macro "x" specified in "R1" and shows the count in column "S".
I am running into 2 problems here.
1. I can not make formula to start from the 4th row and first name to be taken from "B4"
2. I can make formula copy files with names: "B" & "-ACCDOC" & ".pdf" and "B" & "-ACCLINE" & ".pdf" to be copied into folder "CopyTo". I managed to copy 2 files if i entered date in B1 but after that formula was'nt going forward and searching for next files.
Please see code below.
Thank you in advance for you help!
I have created a macro which counts if specific folder "CopyFrom" contains files begining with the name specified in column "B".
Formula takes number of rows to run macro "x" specified in "R1" and shows the count in column "S".
I am running into 2 problems here.
1. I can not make formula to start from the 4th row and first name to be taken from "B4"
2. I can make formula copy files with names: "B" & "-ACCDOC" & ".pdf" and "B" & "-ACCLINE" & ".pdf" to be copied into folder "CopyTo". I managed to copy 2 files if i entered date in B1 but after that formula was'nt going forward and searching for next files.
Please see code below.
Sub CountFiles()
Sheets("MoreThenOneFormulaValueChange").Activate
Dim i As Integer
Dim X As Integer
Dim Folder As String
Dim ExcelFN As String
Dim FileName As String
Dim FileName2 As String
Dim FileName3 As String
Dim NumFiles As Integer
Dim FSO
Dim filPath2 As String
X = Sheets("MoreThenOneFormulaValueChange").Range("R1").Value
For i = 2 To X
NumFiles = 0
Folder = "C:\Users\User\Desktop\CopyFROM\"
ExcelFN = Sheets("MoreThenOneFormulaValueChange").Range("B" & i).Value
FileName = Dir(Folder & ExcelFN & "*" & ".pdf")
While FileName <> ""
NumFiles = NumFiles + 1
FileName = Dir()
Wend
Sheets("MoreThenOneFormulaValueChange").Range("S" & i) = NumFiles
Next i
FileName2 = Dir(Folder & ExcelFN & "-ACCDOC" & ".pdf")
FileName3 = Dir(Folder & ExcelFN & "-ACCLINE" & ".pdf")
filPath2 = "C:\Users\USER\Desktop\CopyTo\"
Set FSO = CreateObject("Scripting.FileSystemObject")
Do While Len(FileName2) > 0
FSO.CopyFile (Folder & FileName2), filPath2
FileName2 = Dir
Loop
Do While Len(FileName3) > 0
FSO.CopyFile (Folder & FileName3), filPath2
FileName3 = Dir
Loop
End Sub
Thank you in advance for you help!