Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Moving files based on cell references

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8,520
Default Moving files based on cell references

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
---------------
Jacob Skaria


"Rookie_User" wrote:

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

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Moving files based on cell references

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.

"Jacob Skaria" wrote:

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
---------------
Jacob Skaria


"Rookie_User" wrote:

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Moving files based on cell references

I made a mistake in my initial request could you review it again.

"Jacob Skaria" wrote:

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
---------------
Jacob Skaria


"Rookie_User" wrote:

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default Moving files based on cell references

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.

"Jacob Skaria" wrote:

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
---------------
Jacob Skaria


"Rookie_User" wrote:

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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Function based on multiple criteria from two cell references ibrokit Excel Worksheet Functions 2 October 13th 07 06:57 PM
Macro for saving files where title is made from cell references [email protected] Excel Discussion (Misc queries) 1 May 12th 07 06:23 PM
Cell References Between sheets or Files Not Working MM Phil Excel Discussion (Misc queries) 3 February 1st 07 10:01 PM
Display cell based on multiple cross-references Petee Excel Worksheet Functions 2 June 15th 06 09:39 PM
Moving rows from one sheet to another based on a particular cell v mm Excel Discussion (Misc queries) 0 November 11th 05 06:29 PM


All times are GMT +1. The time now is 01:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"