0

I have just started vorking with vba, and am slowly getting the hang of it. I have a question as to the posibility of something:

I have an Excel sheet where I have part of the names of a lot of text datasheets I need to copy.

My folder destination is the following: Same folder/Name from column F/Name from column B/text files with the string x in the name...

Is it at all possible to copy files like this from one folder to another?

I am thinking a for loop and a bunch of if statements?

Best Regards

Lonnie

La82
  • 37
  • 4
  • Yes, refer to this: [VBA to copy a file from one directory to another](http://stackoverflow.com/questions/16943003/vba-to-copy-a-file-from-one-directory-to-another). Try to search in [so], check [ask] and provide [mcve] before you post question. – Prisoner Nov 02 '16 at 09:22

1 Answers1

0

To build on Alex's answer, and to confirm what you suspected already, you need to loop through all the files in the originating directory using the Dir command (this tutorial is a bit more readable than the msdn one: https://www.techonthenet.com/excel/formulas/dir.php)

then decide whether to move the file based on a rule (see here for string manipulation: http://www.excel-easy.com/vba/string-manipulation.html)

Finally, if the conditions are fulfilled, use the .copyfile command that Alex suggests in the comments.

Preston
  • 7,399
  • 8
  • 54
  • 84