PDA

View Full Version : Solved: Creating directories from within excel?



KennyJ
05-05-2009, 07:53 AM
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?

Kenneth Hobs
05-05-2009, 08:13 AM
Only you know whether a macro is worth it or not.

This starts from sheet1's A2 down to last row with data.
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

KennyJ
05-05-2009, 10:01 AM
Thank you Kenneth! that was exactly what I needed!