How to copy multiple excel files into different folders based on path

luna007

New Member
Joined
Jan 6, 2021
Messages
10
Office Version
  1. 2010
Platform
  1. Windows
I want to copy multiple excel files into different folders i.e
1656857301774.png


for that i using following code
But after running above code only 1.xlsx is copy to a folder.
I want to copy different excel files to different folder which path is given into coloum B in above picture.

Sub Button1_Click()
' Move any FolderA files (columnA) to dirs in ColumnB
' if they are not already flagged as having been moved in ColumnC.
Const colA = 1
Const colB = 2
Const colC = 3
Const FolderA = "C:\Users\SP\Desktop\Sam\"
Const srcSheet = "Sheet1"
Dim xlS As Excel.Worksheet
Dim xlW As Excel.Workbook
Dim RN As Long ' row number
Dim fName As String
Dim fPath As String
Set xlW = ActiveWorkbook
Set xlS = xlW.Sheets(srcSheet)
RN = 2
fName = Trim(xlS.Cells(RN, colA).Text)
' We'll run thru ColA until we hit a blank
On Error Resume Next ' expect problems if no target Dir
While fName <> ""
If Trim(xlS.Cells(RN, colC).Text) = "" Then
fPath = Trim(xlS.Cells(RN, colB).Text)
If Right(fPath, 1) <> "\" Then fPath = fPath & "\"
If Dir(fPath & fName) <> "" Then Kill fPath & fName
FileCopy FolderA & fName, fPath & fName
DoEvents
If Err.Number <> 0 Then
xlS.Cells(RN, colC).Value = "Failed: Check target Dir"
Err.Clear
Else
xlS.Cells(RN, colC).Value = Now()
End If
End If
' ready for next one
RN = RN + 1
fName = Trim(xlS.Cells(RN, colA).Text)
Wend
MsgBox "Done it!!"
End Sub
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
FilenameSource FolderDestination Folder
aa.xlsxC:\users\textD:\Final\Report
nn.xlsxD:\Com1\Client1E:\Com1\Report
.
.

So on

I Want to move or copy Files from source folder to destination folder
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top