Auto create folders using Excel field entries

13,509

Here is the macro.

  • Make sure the spreadsheet with the Project ID and Start dates is in view (selected) before you run the macro.
  • Set the folder where you want to create these folders in ParentFolderPath

    Sub CreateFolders()
    
    'Variable definations
    Dim FolderListRange As Range
    Dim FolderRange As Variant
    Dim FolderName As String
    Dim ParentFolderPath As String
    
    On Error GoTo Handle
        ' Set the Folder where the individual folders should be created
        ParentFolderPath = "Folders"
    
        Set FolderListRange = ActiveSheet.Range("A2:A64000").SpecialCells(xlCellTypeConstants)
    
        For Each FolderRange In FolderListRange
            If FolderRange.Offset(0, 1).Value = "" Then GoTo Continue
    
            FolderName = ParentFolderPath & "\" & FolderRange.Value & "-" & Format(FolderRange.Offset(0, 1).Value, "dd-mm-yyyy")
    
            If FileSystem.Dir(FolderName, vbDirectory) = vbNullString Then
                FileSystem.MkDir FolderName
            End If
    
    Continue:
        Next
    
    Handle:
    End Sub
    
Share:
13,509

Related videos on Youtube

prrao
Author by

prrao

Data Scientist/Engineer. My primary interests are in building end-to-end, intelligent systems using machine learning, knowledge graphs and NLP.

Updated on September 18, 2022

Comments

  • prrao
    prrao over 1 year

    I need to generate folders containing certain Excel field entries:

    enter image description here

    Additionally, I need to append a date to the folder name based on that entry

    So If I have the above Excel table, I'd need the following set of folders to be generated in the same directory:

    enter image description here

    Is this possible using a macro? Also, in case I add another entry how would I generate another folder only for that entry; for example I add another project CWO-1106:

    enter image description here

    Basically, I'd like to keep updating the Excel sheet and create folders only for the new entries

    Any help would be appreciated. Thanks!

    • Jeff
      Jeff over 7 years
      Is it possible to add subfolders containing the Project-ID? Ex: CWO-1101_QUOTE