Hi everyone,
I am new to this forum even though I have been using it for years. My turn to ask for your help as I couldn't find a solution to my problem so far.
Here is my issue:
I have several files with a given name in a same folder, let's say drive D:
Ex:
D:\AAAA.xls
D:\BBBB.xls
D:\CCCC.xls
I want to have a macro that would allow me to move each .xls file to its designated subfolder (same name). Issue ? The different sub-folders can be located in a different level of sub-folders.
Ex:
Folder AAAA can be located in D:\Folder1\SubFolder1\Subfolder2\AAAA
Folder BBBB can be located in D:\Folder1\SubFolder1\Subfolder2\AAAA\BBBB
Folder CCCC can be located in D:\Folder1\SubFolder2\Subfolder3\CCCC
The logic of the Macro would be:
For each file in a specific folder (D:\ or current folder of the workbook), look for each subfolder in this folder, and when a subfolder with the same name (or at least the n first characters) is found, move this file to this subfolder. Continue with next file and if their is an error, still continue the process until the end and Prompt the Msgbox at the end of the macro:
"The following folders don't exist :
- AAAA
- BBBB
- etc."
NB: each subfolder have already been created and have a unique name.
Most of the time, google is my best friend and I can adapt a macro to fit my requirements, but for this case, I could only find:
- How to move files from a folder to 1 destination sub-folder
- How to move files from a folder to subfolders with the same name (but the macro will not go deeper than the first level of subfolder)
- How to create folders from files and move those files to these folders
I'm sorry if the solution to my problem already exist, but I couldn't find it.
Thanks in advance !
I am new to this forum even though I have been using it for years. My turn to ask for your help as I couldn't find a solution to my problem so far.
Here is my issue:
I have several files with a given name in a same folder, let's say drive D:
Ex:
D:\AAAA.xls
D:\BBBB.xls
D:\CCCC.xls
I want to have a macro that would allow me to move each .xls file to its designated subfolder (same name). Issue ? The different sub-folders can be located in a different level of sub-folders.
Ex:
Folder AAAA can be located in D:\Folder1\SubFolder1\Subfolder2\AAAA
Folder BBBB can be located in D:\Folder1\SubFolder1\Subfolder2\AAAA\BBBB
Folder CCCC can be located in D:\Folder1\SubFolder2\Subfolder3\CCCC
The logic of the Macro would be:
For each file in a specific folder (D:\ or current folder of the workbook), look for each subfolder in this folder, and when a subfolder with the same name (or at least the n first characters) is found, move this file to this subfolder. Continue with next file and if their is an error, still continue the process until the end and Prompt the Msgbox at the end of the macro:
"The following folders don't exist :
- AAAA
- BBBB
- etc."
NB: each subfolder have already been created and have a unique name.
Most of the time, google is my best friend and I can adapt a macro to fit my requirements, but for this case, I could only find:
- How to move files from a folder to 1 destination sub-folder
- How to move files from a folder to subfolders with the same name (but the macro will not go deeper than the first level of subfolder)
- How to create folders from files and move those files to these folders
I'm sorry if the solution to my problem already exist, but I couldn't find it.
Thanks in advance !