Move selected files to selected folder based on excel list

sprs248

New Member
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..
 

harky

Active Member
Cant u just use =CONCATENATE() to create the full path?



File name


Folder name
C:\Users\LENOVO\Desktop\New folder\C:\Users\LENOVO\Desktop\New folder\CSC21251
C:\Users\LENOVO\Desktop\New folder\CSC212512016120120161231.emd
C:\Users\LENOVO\Desktop\New folder\CSC21251
C:\Users\LENOVO\Desktop\New folder\CSC212512017010120170131.emdC:\Users\LENOVO\Desktop\New folder\CSC21251
C:\Users\LENOVO\Desktop\New folder\CSC212512017020120170228.emdC:\Users\LENOVO\Desktop\New folder\CSC21251
C:\Users\LENOVO\Desktop\New folder\CSC213032016120120161231.emdC:\Users\LENOVO\Desktop\New folder\CSC21303
C:\Users\LENOVO\Desktop\New folder\CSC213032017010120170131.emdC:\Users\LENOVO\Desktop\New folder\CSC21303
C:\Users\LENOVO\Desktop\New folder\CSC213032017020120170228.emdC:\Users\LENOVO\Desktop\New folder\CSC21303
C:\Users\LENOVO\Desktop\New folder\CSC217242016050120160531.emdC:\Users\LENOVO\Desktop\New folder\CSC21724
C:\Users\LENOVO\Desktop\New folder\CSC219082016090120160930.emdC:\Users\LENOVO\Desktop\New folder\CSC21908
C:\Users\LENOVO\Desktop\New folder\CSC219082016100120161031.emdC:\Users\LENOVO\Desktop\New folder\CSC21908
C:\Users\LENOVO\Desktop\New folder\CSC219082016110120161130.emdC:\Users\LENOVO\Desktop\New folder\CSC21908

<tbody>
</tbody>
I have large volume of files for moving...
 
Last edited:

harky

Active Member
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


Col A (File located at)
Source
Col B (Move to)
Destination
Filename (What file to be move from COl A)
C:\Users\LENOVO\Desktop\New folderC:\Users\LENOVO\Desktop\New folder\CSC21251CSC212512016120120161231.emd

<tbody>
</tbody>



Moved all files into the first path...
 
Last edited:

harky

Active Member
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:

sprs248

New Member
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,...
 

Some videos you may like

This Week's Hot Topics

  • Get External Data (long shot question!)
    This is likely a long shot but I am wondering if it is at all possible for Excel to somehow 'change' the contents of a URL that is being linked to...
  • Importing multiple excel files into one spreadsheet
    Hi, I'm trying to import multiple excel files (with the same format into a single spreadsheet) so that each day's file is listed underneath the...
  • Cell Formatting
    Good Morning, I need to format a few different cells in the following manners: A1 has to always add a colon (:) after whatever is typed in by a...
  • How to copy multiple rows using If
    Hi all, I'm very new to VBA and have written this simple code to copy certain cells if a certain cell within that row contains any data. I need...
  • Workbook_Change stopped working !
    I am working on an app to speed up & automate processing of Credit Cards statements. After data is input from a CSV file, it is presented to the...
  • VBA If statement
    Dear All, I have two dates, where I'd like a message box to pop, if the dates are between this criteria. [CODE] sDate1 = #10/1/2019#...
Top