Moving files based on cell references

R

Rookie_User

I recognize that this is not truly an Excel thing but it's where the data
lives so I would like to continue to use Excel. I have a column that
contains a filename and another column that contains a path. I would like to
either rename all the files that exist in a specific folder OR copy the files
from source path to target path. The data is structured below. The
source/target path can be split if I need to as in drive letter versus a
path, etc...

I would prefer the macro to cascade down one row at a time once the file has
been copied. If the copy command is difficult then I can just have them
renamed and then I can do a manual copy.

Column
A(Filename) B(Source) C(target)
file123.pdf c:\jason u:\archive
file222.txt c:\jason u:\archive
 
J

Jacob Skaria

Try

Sub MyMacro()
Dim lngRow As Long
For lngRow = 1 To Cells(Rows.Count, "A").End(xlUp).Row
FileCopy Range("B" & lngRow) & "\" & Range("A" & lngRow), _
Range("C" & lngRow) & "\" & Range("A" & lngRow)
Next
End Sub

If this post helps click Yes
 
R

Rookie_User

It works perfectly to what I asked but I believe I left a part out. I
appreciate what you wrote but I also either need to delete the file after
it's moved OR rename it after it's moved so I can then delete it later.
Sorry for missing that in the first place.
 
R

Rookie_User

I get a file not found, even when the file is there. I added a watch
expression and they both look correct - however I am not sure why on the
target folder you adding the file name to. I assumed it would be just a
source and target folder.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top