Move selected files to selected folder based on excel list

sprs248

New Member
Joined
Aug 20, 2019
Messages
18
[TABLE="width: 578"]
<colgroup><col><col></colgroup><tbody>[TR]
[TD]Hi,
I want to move left blue colored files to rightly mentioned red colored folder in all below cases.

File name[/TD]
[TD]




Folder name[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21251[/TD]
[/TR]
[TR]
[TD]CSC212512016120120161231.emd [/TD]
[TD]CSC21251[/TD]
[/TR]
[TR]
[TD]CSC212512017010120170131.emd[/TD]
[TD]CSC21251[/TD]
[/TR]
[TR]
[TD]CSC212512017020120170228.emd[/TD]
[TD]CSC21251[/TD]
[/TR]
[TR]
[TD]CSC213032016120120161231.emd[/TD]
[TD]CSC21303[/TD]
[/TR]
[TR]
[TD]CSC213032017010120170131.emd[/TD]
[TD]CSC21303[/TD]
[/TR]
[TR]
[TD]CSC213032017020120170228.emd[/TD]
[TD]CSC21303[/TD]
[/TR]
[TR]
[TD]CSC217242016050120160531.emd[/TD]
[TD]CSC21724[/TD]
[/TR]
[TR]
[TD]CSC219082016090120160930.emd[/TD]
[TD]CSC21908[/TD]
[/TR]
[TR]
[TD]CSC219082016100120161031.emd[/TD]
[TD]CSC21908[/TD]
[/TR]
[TR]
[TD]CSC219082016110120161130.emd[/TD]
[TD]CSC21908[/TD]
[/TR]
</tbody>[/TABLE]

THANKS...
 
Hi @sprs248,

Try with the below code

Code:
Option Explicit


Sub MoveFiles()
    Dim FSO As Object
    Dim PATH, sourcefile As String, dest, DestinationFolderName, SourceFileName, Filename As String
    Dim lr, x As Long
    
    Set FSO = CreateObject("Scripting.Filesystemobject")
    PATH = Range("D2").Value
    lr = Cells(Rows.Count, "A").End(xlUp).Row
    
    If PATH <> "" Then
        For x = 2 To lr
            SourceFileName = Range("A" & x).Value
            DestinationFolderName = Range("B" & x).Value
            sourcefile = PATH & "\" & SourceFileName & ".emd"
            dest = PATH & "\" & DestinationFolderName & "\" & SourceFileName & ".emd"
            If Not FSO.FileExists(sourcefile) Then
                MsgBox ("File Not Found in " & sourcefile)
            Else
                FSO.MoveFile source:=sourcefile, Destination:=dest
                MsgBox (sourcefile + " Moved to " + dest)
            End If
        Next x
    Else
        MsgBox ("Please Insert PATH in cell 'D2'")
        Exit Sub
    End If
End Sub

Regards
Dhruva
Not understood... Which Cell contains what parameter ... Also after run the code, it asks for content of D Cell..
Kindly help.. i am shortage of time..
 
Upvote 0

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Cant u just use =CONCATENATE() to create the full path?

[TABLE="class: cms_table, width: 578"]
<tbody>[TR]
[TD]

File name[/TD]
[TD]

Folder name[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21251[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC212512016120120161231.emd[/TD]
[TD]
C:\Users\LENOVO\Desktop\New folder\CSC21251[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC212512017010120170131.emd[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21251[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC212512017020120170228.emd[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21251[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC213032016120120161231.emd[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21303[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC213032017010120170131.emd[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21303[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC213032017020120170228.emd[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21303[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC217242016050120160531.emd[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21724[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC219082016090120160930.emd[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21908[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC219082016100120161031.emd[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21908[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC219082016110120161130.emd[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21908[/TD]
[/TR]
</tbody>[/TABLE]
I have large volume of files for moving...
 
Last edited:
Upvote 0
dont understand.

There is only Source & Destination

Move from Folder 1 to Folder 2 tht all..

anyway i am not a scripting but it seen like he wrote what u want


[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD]Col A (File located at)
Source [/TD]
[TD]Col B (Move to)
Destination[/TD]
[TD]Filename (What file to be move from COl A)[/TD]
[/TR]
[TR]
[TD]C:\Users\LENOVO\Desktop\New folder[/TD]
[TD]C:\Users\LENOVO\Desktop\New folder\CSC21251[/TD]
[TD]CSC212512016120120161231.emd[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]



Moved all files into the first path...
 
Last edited:
Upvote 0
There is a table.
Just follow

It actually the same as what he give u just tht he put at col C....
But since this code he hardcord the .ext (u just need to put the filename without ext.)

just put the full path at the excel table

Yes I want this ... but dont know where to edit my source and destination .. Please help.
 
Last edited:
Upvote 0
There is a table.
Just follow

It actually the same as what he give u just tht he put at col C....
But since this code he hardcord the .ext (u just need to put the filename without ext.)

just put the full path at the excel table
Thanks for your guidance,...
 
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