Solved

Create folders and subfolders from cell entries

Posted on 2013-05-27
2
776 Views
Last Modified: 2013-05-27
Dear Experts:

I wonder whether it is possible to create hundreds of folders/subfolders in Windows XP from cell entries.

I have arranged the folders and subfolders to be created as follows in a worksheet:

A2       B2                 C2       D2         E2
K:        MyFolder       10      10-1       10-11
K:        MyFolder       10      10-2       10-21
K:        MyFolder       10      10-3       10-31
etc.     etc.                 etc.     etc.        etc.

The requirements are as follows:

- The path characteristics for the the main folder and the first subfolder are the same for all rows, i.e. 'K:\MyFolder\'
- After that, i.e 'K:\MyFolder\' the folder names vary. A lot of subfolders already exist, i.e. the macro has to skip the creation of already existing ones, i.e. not overwrite them.

I have attached a sample file for your convenience

Help is much appreciated.

Thank  you very much in advance

Regards, Andreas
Create-Folders-From-Cell-Values.xlsx
0
Comment
Question by:AndreasHermle
2 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 39199617
Sub createfolders()
    Dim rw As Range
    Dim cel As Range
    Dim fpath As String
    Dim fnam As String
    For Each rw In Range("B2:E" & Range("A" & Rows.Count).End(xlUp).Row).Rows
        fpath = rw.Offset(, -1).Cells(1, 1)
        For Each cel In rw.Cells
            fpath = fpath & "\" & cel
            fnam = Dir(fpath, vbDirectory)
            If fnam = "" Then MkDir fpath
        Next cel
    Next rw
End Sub
0
 

Author Closing Comment

by:AndreasHermle
ID: 39199671
ssaqibh:

I am so damned happed to be able to turn to this forum for expert advice.

This will save me hours of creating folders manually. I have been given great solutions on many occassions making my life much easier.

ssaqibh, thank you so much for your great and professional help. You are one of the experts with very concise coding.

Again, great job, well done!

Regards, Andreas
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Dealing with unintended Excel Active-X resizing quirks (VBA code simulates "self correction") David Miller (dlmille) Intro Not everyone is a fan of Active-X controls in spreadsheets (as opposed to the UserForm approach, the older Form controls …
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now