+ Reply to Thread
Results 1 to 13 of 13

Move Multiple Files into Specific Location Based On Criteria

  1. #1
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Move Multiple Files into Specific Location Based On Criteria

    Hi all

    I was wondering if I could get some help on this. I want to move multiple files into sub folders of the same name using Excel VBA. So for example, If I have workbooks called Barry Allen and Wally West, I want to move them into sub folders called Barry Allen and Wally West using Excel VBA.

    I hope that makes sense.

    Thanks,

    Shak

  2. #2
    Registered User
    Join Date
    10-30-2018
    Location
    London
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Move Multiple Files into Specific Location Based On Criteria

    Hi Shak,

    Just to be sure i get your meaning
    you have multiple files with same name? is the difference? eg. wally west,wally west(1), wally west(2) OR wallywestsomething, wallywestorOther etc).
    So you have say 2 folders, 1 = Barry Allen, 2 = Wally West.
    you have multiple workbook files relating to either of these two folders.
    these files are identifiable as belonging to these 2 folders as they have the same names somewhere in the naming text string (workbook file name)

    1. are all these workbook files in one folder at the moment? (so as to tell vba path of source)

  3. #3
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Re: Move Multiple Files into Specific Location Based On Criteria

    Hi Brian

    Thank you for your reply. I have multiple files with different names like Barry Allen and Wally West (all saved in the same location), all these files have corresponding sub folders in a different location, and I essentially want to match and move the file into the corresponding sub folder that matches the name of the file (The sub folders are in the same location as well)...

    Does that make sense?

  4. #4
    Registered User
    Join Date
    10-30-2018
    Location
    London
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Move Multiple Files into Specific Location Based On Criteria

    hey shak

    try this code out

    Please Login or Register  to view this content.
    Last edited by Brian Itotia; 12-13-2018 at 03:46 PM.

  5. #5
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Re: Move Multiple Files into Specific Location Based On Criteria

    Thanks, Brian! I've used, I didn't get any errors, or at least nothing that I couldn't fix, but it didn't move the workbooks into the sub folders of the same name. I've amended the code slightly. See below: - Any ideas?

    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    10-30-2018
    Location
    London
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Move Multiple Files into Specific Location Based On Criteria

    this line

    If Left(fso.GetFileName(Thisfile.Path), 3) = "sql" Then

    sql should be your file name

  7. #7
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Re: Move Multiple Files into Specific Location Based On Criteria

    Hi Brian

    Sorry new-ish to VBA, so sorry if I am being an idiot or simple. So should the file be named 'sql' rather the examples (Barry Allen or Wally West) I gave above or am I missing the point? Do I need to amend file names?

  8. #8
    Registered User
    Join Date
    10-30-2018
    Location
    London
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Move Multiple Files into Specific Location Based On Criteria

    ok.
    no worries.
    firstly, have you confirmed that the code is pointing to your specific source folder and target folder paths.
    these two lines:
    Please Login or Register  to view this content.
    if the path is to your satisfaction, comment the two lines back out.

  9. #9
    Registered User
    Join Date
    10-30-2018
    Location
    London
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Move Multiple Files into Specific Location Based On Criteria

    Now the if condition in question is the search through the files in the old file path folder (olfpath) and uses their file names to find a match string of text.
    so..
    Please Login or Register  to view this content.
    to answer your previous question, this line: Left(fso.GetFileName(Thisfile.Path), 3) = "sql" is the file name string checker.
    it says look in the olfpath and test the first three characters of all the files in the olfpath folder.
    if any of those files names begin with "sql" then copy .......
    i believe yours are different, i would imagine something like: Left(fso.GetFileName(Thisfile.Path), 15) = "wally*"
    This would mean that it would be nice to have a set standard for your file names for ease. (this is why i asked how your files are named yesterday.)
    there is still a bit more to do to the code to adapt it to check for different cases to test against eg if the file is a diferent name change folder path of paste.

  10. #10
    Registered User
    Join Date
    10-30-2018
    Location
    London
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Move Multiple Files into Specific Location Based On Criteria

    Also, i believe the file paths in the variables: olfpath and newfpath are crucial to this and i must admit i have never referenced a range in a file path as you have so, very interested to know what the results of your debug.print line for these variables is.

  11. #11
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Re: Move Multiple Files into Specific Location Based On Criteria

    Hi Brian

    Still can't seem to get it to work, I'll keep trying. In the meantime, just to let you know, the File Paths worked fine.

  12. #12
    Registered User
    Join Date
    10-30-2018
    Location
    London
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Move Multiple Files into Specific Location Based On Criteria

    ok.
    just to summarize for clarity, the code i sent at thread #4 does this:
    checks the files in the download folder on C drive, steps through the files in the whole folder until it reaches any files whose first three letters starting from the left have "sql" in their string.
    it copies these files to the new path which in my code at thread #4 is in the downloads folder in a folder called "excel".
    it copies all files that have sql as the three first letters of their filenames.
    BEFORE:
    PICS4FORUM.png
    RESULT AFTER:
    PICS4FORUM1.png
    leftclick image and open in new tab for larger size image.
    once tested that code works can change the copy file code to move file instead.
    Hope it helps.
    Last edited by Brian Itotia; 12-14-2018 at 08:26 AM.

  13. #13
    Registered User
    Join Date
    10-30-2018
    Location
    London
    MS-Off Ver
    excel 2010
    Posts
    53

    Re: Move Multiple Files into Specific Location Based On Criteria

    if you get the chance shak, please explain what your intention is with the string paths held by the variables olfpath and newfpath. i mean this with regard to the sheet and range reference, reason is there may be an alternative way to do that.
    secondly, the if condition would also be interesting to see what your changes are.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Copy & Move multiple certain name specific files to another Folder.
    By kandoo1 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 06-22-2016, 11:02 AM
  2. Replies: 17
    Last Post: 05-23-2016, 11:04 PM
  3. Replies: 3
    Last Post: 05-17-2016, 05:14 PM
  4. split text files stored in some location to multiple files based on a condition
    By GIRISH_KH in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-01-2013, 11:32 AM
  5. Replies: 0
    Last Post: 07-11-2013, 02:08 AM
  6. Macro to move rows, row by row, based upon specific criteria.
    By luke8182 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 02-20-2012, 01:05 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1