Consulting

Results 1 to 3 of 3

Thread: Solved: Creating directories from within excel?

  1. #1
    VBAX Regular
    Joined
    May 2008
    Posts
    26
    Location

    Solved: Creating directories from within excel?

    I have a spreadsheet with part numbers in column A and descriptions of those parts in column C. What I would like to do is create a macro that will create Sub-Directories named with the part number then the description after it like this:

    -Example Directory Name-
    12345 (Part Description)

    Inside of a directory called "TESTERS"

    "12345" will be in Column A without ""

    "Part Description" will be in Column C again no "" and will not have the () that I need added.

    Is this something that can be done? Does anyone have a link to some code to get me started? or would it be faster to just create the directories 1 by 1 manually instead of trying to make a macro?

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Only you know whether a macro is worth it or not.

    This starts from sheet1's A2 down to last row with data.
    [VBA]Sub MakeSubFolders()
    Dim sCell As Range, rootFolder As String

    rootFolder = "c:\TESTERS\"
    If Dir(rootFolder, vbDirectory) = "" Then
    MsgBox "Rootfolder: " & rootFolder & vbLf & "Does Not Exist", vbCritical, "Macro Ending"
    Exit Sub
    End If

    On Error Resume Next
    For Each sCell In Sheets("Sheet1").Range("A2", _
    Sheets("Sheet1").Range("A" & Rows.Count).End(xlUp))
    MkDir rootFolder & sCell.Value & " (" & sCell.Offset(0, 2).Value & ")"
    Next sCell
    End Sub[/VBA]

  3. #3
    VBAX Regular
    Joined
    May 2008
    Posts
    26
    Location
    Thank you Kenneth! that was exactly what I needed!

Posting Permissions

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