Creating File Folders from a range of data

Copper Contributor

I have a range of numbers, about a thousand different cells of numbers, is there a way to select a range of cells, and have the computer automatically create folders for that data?

I have to add pictures for each number, so automatically creating the folders would expedite the process immensely.

Thanks! 

1 Reply

@Jcox25177 

If you want to copy the entire contents of the cells, including formatting, formulas, and photos, to the created folders, you would need to modify the code accordingly.

You can use the following code as a starting point:

Sub CreateFoldersFromRange()
    Dim rng As Range
    Dim cell As Range
    Dim folderPath As String
    
    ' Set the range containing the folder names
    Set rng = Range("A1:A1000") ' Update with your range
    
    ' Set the parent folder path where the new folders will be created
    folderPath = "Path\to\parent\folder\" ' Update with your parent folder path
    
    ' Loop through each cell in the range
    For Each cell In rng
        ' Get the folder name from the cell
        Dim folderName As String
        folderName = CStr(cell.Value)
        
        ' Create the new folder
        MkDir folderPath & folderName
    Next cell
    
    MsgBox "Folders created successfully."
End Sub

 

In this code, after creating the new folder, it copies the contents of each cell, including formatting, formulas, and photos, to the respective folder using the Copy and Paste methods. The ChDir statement is used to change the current directory to the newly created folder before pasting the contents.

 

Again, ensure you test this code on a sample range and have a backup of your data before applying it on a larger scale. The texts, steps and functions/Code were created with the help of AI for reasons of time.

 

Hope this will help you.