ChaseHammer
New Member
- Joined
- Jan 18, 2024
- Messages
- 3
- Office Version
- 365
- Platform
- Windows
Hi - First time on this forum and was hoping someone could help me out...
I am trying to copy any and all pdf files with a prefix of TT Plan from a single source folder (specified in cell C3) to a series of destination folders based on a specific main directory, then subfolder names as the job numbers in cells B8 through however many job numbers I have.
Below is what I was trying, though I know this is setup incorrectly for the destination folder.
Sub CopyFiles()
Dim LastRowInA As Long
Dim Cel As Range
Dim Rng As Range
Dim DestinationFolder As String
Dim FileExtention As String
Dim SourceFile As String
Dim SourceFolder As String
On Error Resume Next
SourceFolder = TTPlanCopy.Range("C4") & "\"
FileExtention = "pdf"
DestinationFolder = "F:\UFP Design\Report Testing\Jobs\"
If Dir(DestinationFolder, vbDirectory) = 0 Then
MsgBox ("Job Folder does not exist")
Exit Sub
End If
SourceFile = Dir(SourceFolder & "TT Plan*." & FileExtention)
LastRowInB = Range("B" & Rows.Count).End(xlUp).Row
Set Rng = Range("B8:B" & LastRowInB)
With Rng
For Each Cel In Rng
Do While SourceFile Like "TT Plan*"
FileCopy SourceFolder & SourceFile, DestinationFolder & Cel
SourceFile = Dir
Loop
Next
End With
End Sub
I am trying to copy any and all pdf files with a prefix of TT Plan from a single source folder (specified in cell C3) to a series of destination folders based on a specific main directory, then subfolder names as the job numbers in cells B8 through however many job numbers I have.
Below is what I was trying, though I know this is setup incorrectly for the destination folder.
Sub CopyFiles()
Dim LastRowInA As Long
Dim Cel As Range
Dim Rng As Range
Dim DestinationFolder As String
Dim FileExtention As String
Dim SourceFile As String
Dim SourceFolder As String
On Error Resume Next
SourceFolder = TTPlanCopy.Range("C4") & "\"
FileExtention = "pdf"
DestinationFolder = "F:\UFP Design\Report Testing\Jobs\"
If Dir(DestinationFolder, vbDirectory) = 0 Then
MsgBox ("Job Folder does not exist")
Exit Sub
End If
SourceFile = Dir(SourceFolder & "TT Plan*." & FileExtention)
LastRowInB = Range("B" & Rows.Count).End(xlUp).Row
Set Rng = Range("B8:B" & LastRowInB)
With Rng
For Each Cel In Rng
Do While SourceFile Like "TT Plan*"
FileCopy SourceFolder & SourceFile, DestinationFolder & Cel
SourceFile = Dir
Loop
Next
End With
End Sub