+ Reply to Thread
Results 1 to 5 of 5

search for a string in a filename that contains a date and move to subfolder for that date

  1. #1
    Registered User
    Join Date
    07-11-2013
    Location
    Sac, CA
    MS-Off Ver
    Excel 2010
    Posts
    3

    search for a string in a filename that contains a date and move to subfolder for that date

    Hi, first time poster, great info on this site!
    I need a macro to search for a string in a filename that contains a date and move it to a subfolder for that date.
    Issue: 6 teams each have a folder with around 5,000 spreadsheets. Filenames are in the following format: LastName, FirstInitial. MM-DD-YYYY- Rev -000.xlsm. The filepath is long, so I’ll represent as M:\A\B\D\E\F\G\Team 1\Staff Summaries. The range of dates in the filename is from 2013 to present.
    Goal: I need to organize the files to a folder by year, with monthly subfolders.
    I have a macro cobbled together from this and other sites to create the folder and subfolders in the Staff Summaries folder so that I’ll have a folder named 2013 with monthly subfolders, and so on, through 2017. It creates the folder and subfolders in a user defined file path.

    Please Login or Register  to view this content.
    Can someone create a macro or modify the above to move each file to the appropriate subfolder based on the date that’s in the filename? For example, the file named Smith, J. 03-15-2015- Rev -001.xlsm residing in M:\A\B\D\E\F\G\Team 1\Staff Summaries needs to be moved to M:\A\B\D\E\F\G\Team 1\Staff Summaries\2015\Mar.

    Thanks, Dave

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: search for a string in a filename that contains a date and move to subfolder for that

    Try this. The code is not tested. First test this on a few test files before using on your 5000 files.

    Please Login or Register  to view this content.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: search for a string in a filename that contains a date and move to subfolder for that

    Try this
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    07-11-2013
    Location
    Sac, CA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: search for a string in a filename that contains a date and move to subfolder for that

    Thanks AlphaFrog and jindon for your input. I'll test these with test data. I have 6 teams with about 5000 files each and this will defiantly be a lot better than manually sorting the files.

  5. #5
    Registered User
    Join Date
    07-11-2013
    Location
    Sac, CA
    MS-Off Ver
    Excel 2010
    Posts
    3

    Re: search for a string in a filename that contains a date and move to subfolder for that

    So far both solutions are working well. The test data is 24,055 files. Execution times are similar at around 50 seconds. AlphFrog's code worked as he wrote it but I slightly modified it regarding the SourceFolder variable by changing it to ParentFolder in order to use the path already referenced from the selection in the Folder Dialog Box. This works for my situation since the resulting subfolders need to be created in the originally chosen path.

    I didn't modify jindon's code because I'm not familiar with arrays and it already creates the folders in the appropriate path. The result produced by jindon's code revealed an error made by one of the staff. I was surprised to see a folder for 1983 in the result. Somehow, one of the staff coded her file with the year 1983.

    Anyway, I am happy with both responses. Thank you both for excellent solutions.

+ 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. Search column for string and date then search adjacent cell and pop up message
    By ftwobtwo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-06-2014, 09:55 AM
  2. VBA code needed to move from Outlook 2010 subfolder to Symantec Vault subfolder
    By Marijke in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 01-09-2014, 12:14 PM
  3. [SOLVED] Open an xlsx with most recent date in filename, run my data pulling macro, then move file
    By alanwu07 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-31-2013, 05:24 AM
  4. Replies: 1
    Last Post: 09-20-2012, 03:22 PM
  5. Excel VBA - Hold String in Sheet1 until specified Date then move to Sheet2
    By Nu2Java in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-17-2012, 10:49 PM
  6. Search for Filename with Date and Open File
    By Gingeiko in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-29-2011, 08:11 PM
  7. Macro search by date and move row
    By jj33002 in forum Excel General
    Replies: 4
    Last Post: 04-06-2007, 08:12 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