Excel (2007) VBA - Filecopy only files listed in an excel sheet to different specified folder path

jika

New Member
Joined
Feb 9, 2011
Messages
2
Good Morning!

I have an upload sheet which contains the following

Column A will contain either Y or N, Y if the file is to be copied upon run macro or N, if needs to be ignored
Column B - path and file name to be copied
Column C - destination path

I've been trying to figure out how to code a macro that will copy files listed in column B of the upload sheet to the destination path in column C provided that I place Y in Column A. Data in column C can vary. I also want to add the date and time in the file name of the copied file in the destination path provided. Repeat procedure until last file (Column B) with Y in Column A has been copied to the path in Column C. Here's what I got so far but it only works if a path is listed in Colum B and copies all the files from the listed path. :confused:

Anticipating thanks for your help. :)

Code:
Sub FileCopytest()
   Dim MySource01
   Dim MyDestination01
   Dim fn
   On Error Resume Next   ' if file is open it will not be copied
   MySource01 = Sheets("Upload").Range("B2")
   MyDestination01 = Sheets("Upload").Range("C2")
 
      If Right(MySource01, 1) <> "\" Then MySource01 = MySource01 & "\"
   If Right(MyDestination01, 1) <> "\" Then MyDestination01 = MyDestination01 & "\"
 
 
   fn = Dir(MySource01 & "*.*")
 
   Do While Not fn = ""
 
   FileCopy MySource01 & fn, MyDestination01 & fn
 
   fn = Dir()
   Loop
End Sub
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
Hi VBA Gurus,

If you have questions about what I need to do, please don't hesitate to ask. I badly need your help on this. Thanks.
 
Upvote 0

Forum statistics

Threads
1,214,424
Messages
6,119,400
Members
448,893
Latest member
AtariBaby

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