Consulting

Results 1 to 3 of 3

Thread: Make File Folders using data from column range

  1. #1
    VBAX Regular
    Joined
    Aug 2014
    Posts
    49
    Location

    Make File Folders using data from column range

    Hello All!

    I need help with using the VBA on excel to create folders with specific names in the file loaction in which the excel workbook is saved.

    For example:

    If i have my excel workbook saved in the file location C:\Users\zlerp\Desktop

    --And in this workbook contains data in column A from A2 to Last used Row in A (the range changes)

    the data is as follows:
    A2 = 1234
    A3 = ABCD
    A4 = XXXX
    A5 = YYYY

    What macro can be created that will Make Directories (Folders) in C:\Users\zlerp\Desktop (where the workbook is saved)
    and have folders named:
    1234
    ABCD
    XXXX
    YYYY


    So the final result is to have 4 different folders in the same file location as the workbook (which will be a delimited .txt in my situation) named whatever is in Column A from A2 to the last row used by column A.

    PS: THERE WILL BE DUPLICATE VALUES IN COLUMN A.

    Thank you for your help!

  2. #2
    VBAX Tutor
    Joined
    Mar 2014
    Posts
    210
    Location
    Sub MakeMyFolders()
    Dim vDir, vRoot
    vRoot = ActiveWorkbook.Path & "\"
    If vRoot = "\" Then
       MsgBox "No folder given", vbCritical, "Save the File"
       Exit Sub
    End If
    
    Range("A2").Select
    While ActiveCell.Value <> ""
       vDir = vRoot & ActiveCell.Value
       MakeDir vDir
       
       ActiveCell.Offset(1, 0).Select  'next row
    Wend
    End Sub
    Private Sub MakeDir(ByVal pvDir)
    Dim fso
    On Error Resume Next
    Set fso = CreateObject("Scripting.FileSystemObject")
    If Not fso.FolderExists(pvDir) Then fso.CreateFolder pvDir
    Set fso = Nothing
    End Sub

  3. #3
    VBAX Regular
    Joined
    Aug 2014
    Posts
    49
    Location
    Wow! Thank you soo much! It works perfectly!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •