PDA

View Full Version : [SOLVED:] Copy files by name from a folder to another



Efusu
04-24-2020, 08:27 AM
Hi. I have a list with specific file names (Sheet "Attachments list", range B2:B603). I need a macro that copies the files in this list from a source folder (that contains those files and a bunch of other files) to a destination folder.
Help pls.:banghead::banghead:
Thanks!

paulked
04-24-2020, 07:40 PM
Hi and welcome to the forum

See here (https://answers.microsoft.com/en-us/msoffice/forum/all/vba-excel-find-matching-list-files-and-copy-to/47ee062e-b62c-40e0-90cc-495828da0790)

Efusu
04-27-2020, 03:13 AM
Thank you, it worked!

paulked
04-27-2020, 04:13 AM
You're welcome! :thumb

You can mark it 'Solved' by using the Thred Tools above.

binu.b
04-27-2020, 05:30 AM
Dim filelist As Variant
Dim i As Long
Dim filetocopy As String
Dim copysource As String
copysource = SourceDir
filelist = ActiveWorkbook.Sheets(1).Range("A1").CurrentRegion.Value
For i = 2 To UBound(filelist)
fname = Dir$(copysource & "*.*")
While fname <> ""
If UCase(fname) = UCase(filelist(i, 1)) Then
FileCopy copysource & fname, "C:\Copyto" & fname
End If
fname = Dir$()
Wend
Next i

paulked
04-27-2020, 05:50 AM
Binu, code is easier to read if it is indented and you should use Code Tags to wrap code, even copied code!