Need help with making folders from mutiple cell entries using VBA

Dynequip

New Member
Joined
Feb 18, 2013
Messages
6
Hi,

I am a new to VBA coding, and would appreciate some help. I am trying to create folders in a directory using data from one column, adding a space, then data from another column as a folder name. as an example data from column C + Space(1) + data from column E would make a folder named C E. I also want each folder to have four common sub directories. Here is the code I have compiled using other peoples VBA code. When I run the macro it gives me an error "run-time error 76, path not found" after the first couple of folders have been created.

Code:
Sub MakeFolder()
Dim xdir As String
Dim fso
Dim lstrow As Long
Dim i As Long
Set fso = CreateObject("Scripting.FileSystemObject")
lstrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
Application.ScreenUpdating = False
For i = 2 To lstrow
xdir = "S:\Customer Files\" & Range("C" & i) & Space(1) & Range("E" & i).Value
If Not fso.FolderExists(xdir) Then fso.CreateFolder (xdir)
If Not fso.FolderExists(xdir & "\Drawings") Then fso.CreateFolder (xdir & "\Drawings")
If Not fso.FolderExists(xdir & "\Pictures") Then fso.CreateFolder (xdir & "\Pictures")
If Not fso.FolderExists(xdir & "\Manuals") Then fso.CreateFolder (xdir & "\Manuals")
If Not fso.FolderExists(xdir & "\Quotes") Then fso.CreateFolder (xdir & "\Quotes")
Next
Application.ScreenUpdating = True
End Sub
 
Last edited:

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Your code works for me. The code fails with the same "run-time error 76, path not found" if the C and/or E cell contains a character which is invalid in a Windows folder or file name, for example "/". Therefore I would check whether there are invalid characters in the C and E cells.
 
Upvote 0
Awesome! I found that there was a space after one of the names in a cell, after i deleted the space it works. I would also like to add a code that would add a link to the first folders created, and not the second set of folders ie drawings pictures ect. Then when viewing the excel sheet you could just click the link that then opens the folder.
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top