Loop through range to create new files with dynamic subfolders

Registration date
Thursday October 1, 2020
Last seen
October 12, 2020
 Mo_1001 -
I would like to have suggestions for a VBA code that does this:

Generate an Excel file for each contract number. When copying the contract number to a specific cell in the workbook, a personalized Excel file is created for this contract number. I would thereafter like to save this personalized file in a distinct Excel file. The Excel file must be saved in a specific folder which path could be referred to the contract number, that is the information about the specific path would already be in the "model" Excel file.

Therefore, the steps would be :

1- In the sheet, "Info_base", copy the 1st contract number on top of a list which is saved on the range of cells A3:A22,
2- Copy this contract number, on another sheet "Formulaire", at cell D22. With this copy a personalized file is being created for that contract number.
3- Save this personalized file in a specific subfolder (where path could be a field in the "Info_base" database.) The name of the file would look like:
2021-01_Analysis_(Name of group)_#(contract number)(Note : Group name is also a field in the "Info_base" database.
4- Once the personalized Excel file had been saved, need to go back to the model "Excel" file.
5- Then redo steps 1 to 4, for each contract number (19 times)

I don't think it is so complicated for anyone who is a bit more used to code VBA loop than me. I think we might need to declare the range of cells where "Info_Base" is as a 2 dimensions table...but maybe not ?

Anyway, I would appreciate an helping hand on this. Thanks in advance !

1 reply

Registration date
Sunday September 12, 2010
Last seen
October 15, 2020
Hi Mo,

Some questions for you:
1) What do you mean by "personalized file"? Is that a new file with the "Formulaire" sheet copied into it?
2) Where are the subfolder names located on the "Info_base" sheet?
3) Where are the Groupnames located on the "Info_base" sheet?

Best regards,
Thank you

Glad we were able to help! Love us? Write us a review! Rate CCM

CCM 2942 users have said thank you to us this month

Thank you Trowa ! here are my answers to your questions :
1- It will include all the sheets from the "model" excel file, including '"Formulaire"
2- The subfolder names would be in the 29th column, that is column AC, with the contract numbers being in column A of the sheet "Info-base"
3- The groupnames are on column B, just right beside the contract numbers.

Thanks again