Skip to main content

How to quickly create folders based on cell values in Excel?

Supposing you have a list of staff names in a range of a worksheet, and now you want to create some folders for each of them in the cells to record their information. If you create the folders one by one, it will waste a lot of time. But how could you quickly create these folders? Today, I will introduce you some quick tricks:

Create folders based on cell values with VBA code

Quickly create folders based on cell values with Kutools for Excelgood idea3


Create folders based on cell values with VBA code

For example, I have a range of names in a worksheet, I want to create folders for each of them, and save them to a specified path, with the VBA code, I can finish this task.

1. Put the active workbook into a specific directory which you will place the created folders into. Open the workbook and select the range of cells that you want to use.

doc-create-folders1

2. Click Developer > Visual Basic, a new Microsoft Visual Basic for applications window will be displayed, click Insert > Module, and input the following code into the Module:

VBA code: create folders based on cell values

Sub MakeFolders()
Dim Rng As Range
Dim maxRows, maxCols, r, c As Integer
Set Rng = Selection
maxRows = Rng.Rows.Count
maxCols = Rng.Columns.Count
For c = 1 To maxCols
r = 1
Do While r <= maxRows
If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then
MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))
On Error Resume Next
End If
r = r + 1
Loop
Next c
End Sub

3. Click doc-multiply-calculation-3 button to execute the code. All the selected cells have been created to folders with their values. And the folders are placed into the path as same as the active workbook. See screenshot:

doc-create-folders2


Quickly create folders based on cell values with Kutools for Excel

It is easy and convenient for you to create folders based on cell vales if you use the tool- Kutools for Excel.

Kutools for Excel, with more than 300 handy functions, makes your jobs more easier. 

After installing Kutools for Excel, please do as below:(Free Download Kutools for Excel Now!)

1. Select the range that you want to create folders.

2. Click Kutools Plus > Import / Export > Create Folders from Cell Contents…, see screenshot:

doc create folder 1

3. In the Create Folders from Cell Contents dialog box, click doc-create-folders3button to specify the path you want to save the folders. Seen screenshot:

doc create folder 2

4. Click OK. And a prompt box will remind you how many folders have been created. See screenshot:

doc create folder 3

5. Click OK. And all of the values in the selected range have been created folders in the specified folder.
doc create folder 4


List all file names from a folder into a sheet

to know more about this function.

Here is an utility in Kutools for Excel – Filename List can list all file names of a folder in a sheet, if you are interested in it, please go on reading.

After installing Kutools for Excel, please do as below:(Free Download Kutools for Excel Now!)

1. Click Kutools Plus > Import/Export > Filename List.
doc create folder 5

2. In the Filename List dialog, select a folder you want to list its files, the check All files or Specify option as you need in Files type section.
img src="//cdn.extendoffice.com/images/stories/doc-excel/create-folders/doc-create-folder-6.png" alt="doc create folder 6" />

3. Click Ok, a new sheet is created with all file names and some relative information.
doc create folder 7

Best Office Productivity Tools

Supercharge Your Spreadsheets: Experience Efficiency Like Never Before with Kutools for Excel

Popular Features: Find/Highlight/Identify Duplicates   |  Delete Blank Rows   |  Combine Columns or Cells without Losing Data   |   Round without Formula ...
Super Lookup: Multiple Criteria VLookup    Multiple Value VLookup  |   VLookup Across Multiple Sheets   |   Fuzzy Lookup ....
Advanced Drop-down List: Quickly Create Drop Down List   |  Dependent Drop Down List   |  Multi-select Drop Down List ....
Column Manager: Add a Specific Number of Columns     Move Columns   |   Unhide Columns   |   Compare Columns to Select Same & Different Cells ...
Featured Features: Grid Focus   |  Design View   |   Big Formula Bar    Workbook & Sheet Manager   |  Resource Library (Auto Text)   |  Date Picker   |  Combine Worksheets   |  Encrypt/Decrypt Cells    Send Emails by List   |  Super Filter   |   Special Filter (filter bold/italic/strikethrough...) ...
Top 15 Toolset12 Text Tools (Add Text, Remove Characters, ...)   |   50+ Chart Types (Gantt Chart, ...)   |   40+ Practical Formulas (Calculate age based on birthday, ...)   |   19 Insertion Tools (Insert QR Code, Insert Picture from Path, ...)   |   12 Conversion Tools (Numbers to Words, Currency Conversion, ...)   |   7 Merge & Split Tools (Advanced Combine Rows, Split Cells, ...)   |   Many More...

Kutools for Excel boasts over 300 features, ensuring that what you need is just a click away...

Supports Office/Excel 2007-2021 & newer, including 365   |   Available in 44 languages   |   Enjoy a full-featured 30-day free trial.

kte tab 201905


Office Tab Brings Tabbed interface to Office, and Make Your Work Much Easier

  • Enable tabbed editing and reading in Word, Excel, PowerPoint, Publisher, Access, Visio and Project.
  • Open and create multiple documents in new tabs of the same window, rather than in new windows.
  • Increases your productivity by 50%, and reduces hundreds of mouse clicks for you every day!
Comments (59)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
is it possible to introduce a condition where if that condition is met the module can create 2 folders (each using a different path)?
if the first list of folders is in the A column then the condition occurs in the U column. The conditional criteria is whether the cell is empty or not.
if the condition is not met the module only makes one folder based on the selection.
This comment was minimized by the moderator on the site
Hi, a_c, sorry I have not found a method can solve this job yet.
This comment was minimized by the moderator on the site
Thank you very much
This comment was minimized by the moderator on the site
Thanks a lot! Your VBA code is really super
This comment was minimized by the moderator on the site
Is it possible to import data from a word to excel on colors algorythme? So, I spell the cities with red and countries with blue in a word, and the to import only these to excel. I don’t know if I made myself clear. Thanks
This comment was minimized by the moderator on the site
Thank you, this has saved me literally days of work.
This comment was minimized by the moderator on the site
Hello,


For the following code it shows error in

MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))



It says Runtime error 76 path not found



Can someone please help me with this?

There are no unsupported characters in the file path.
Not sure what could be the problem

Thanks for the help!
This comment was minimized by the moderator on the site
thank you , time saved
This comment was minimized by the moderator on the site
Thanks you. Tried the first method. Works perfectly.
This comment was minimized by the moderator on the site
Hi,
For the following code it shows error in
MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))

It says Runtime error 76 path not found

Can someone please help me with this?
This comment was minimized by the moderator on the site
Hi, make sure the folder name doesn't contain unsupported characters.
This comment was minimized by the moderator on the site
Could someone edit the VBA code to display a message if the folder already exists and prevent from recreating it:

Sub MakeFolders()
Dim Rng As Range
Dim maxRows, maxCols, r, c As Integer
Set Rng = Selection
maxRows = Rng.Rows.Count
maxCols = Rng.Columns.Count
For c = 1 To maxCols
r = 1
Do While r <= maxRows
If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then
MkDir (ActiveWorkbook.Path & "\" & Rng(r, c))
On Error Resume Next
End If
r = r + 1
Loop
Next c
End Sub
This comment was minimized by the moderator on the site
Hi, I copied the code above, but get an error "Bad file name or number (Error 52)" on this code line:
If Len(Dir(ThisWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then

Any idea, what the issue could be?
This comment was minimized by the moderator on the site
GREAT..!!

Really really help me bro..

God Bless You All..
This comment was minimized by the moderator on the site
It works great,Thank you
This comment was minimized by the moderator on the site
Website looked a bit sketchy but this worked and saved me a lot of frustration. Thank you!
This comment was minimized by the moderator on the site
it worked exactly as told.
thanks!
This comment was minimized by the moderator on the site
I am trying to use this file in a sharepoint folder to create folders. But I get the path error. Is it possible to change the code to work in a sharepoint folder the file is located ?
This comment was minimized by the moderator on the site
Is it possible to create a folder>subfolder import structure? Allowing me to have all the top level folders and their sub folders import all at once? They will be all the same.
This comment was minimized by the moderator on the site
Sorry I do not get your point. Do you mean to create folder and subfolder based on cell values or to import folder and subfolder name in Excel? If the last one, yuo can apply Kutools for Excel's Create Filename List.
This comment was minimized by the moderator on the site
Hi All, I'm a super newb, like some of you I don't know how to change the destination of where these files are created. The files are currently being created on my Desktop, is there a way I could change the destination to a SharePoint?
This comment was minimized by the moderator on the site
If you dont have enterprise licence of ms excel then its bit difficult, try the trick in the video and share like or subscribe



https://youtu.be/1WAQWm7UPBY
This comment was minimized by the moderator on the site
Thank you very very much! you just made me save like 3 hours of work!
This comment was minimized by the moderator on the site
How to make sub-folders also in this VBA?
This comment was minimized by the moderator on the site
Not working using Excel for Mac (v15.31)... run-time error '53': File not found. Is the "\" format not applicable on Mac? Bounces error on this line of code: If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0
This comment was minimized by the moderator on the site
Did you ever get this figured out?
This comment was minimized by the moderator on the site
Just saved me a few hours of work. I would fax you a beer if I knew your number!!!
This comment was minimized by the moderator on the site
Dude, you rock!! Thanks a million
This comment was minimized by the moderator on the site
Dude, you are awesome! Thank you ever so much!
This comment was minimized by the moderator on the site
Worked like a charm, but is there a way to create subfolders?
This comment was minimized by the moderator on the site
hi , i m a newbie excel shoe error 52 while debugging this plz help
This comment was minimized by the moderator on the site
Thanks for this. works fine
This comment was minimized by the moderator on the site
Cheers! Great function!
This comment was minimized by the moderator on the site
Thanks a ton Dude,,, its working...
This comment was minimized by the moderator on the site
you just saved me a lot of time pal
This comment was minimized by the moderator on the site
Thanks a lot for this KUTOOLS & Enterprise tabs ......time saving tool..
This comment was minimized by the moderator on the site
You are awesome. It worked. Thanks.
This comment was minimized by the moderator on the site
Nice Job.....Excellent
This comment was minimized by the moderator on the site
I'm trying to add multiple columns together when creating a folder. Any suggestions on how to do this? e.g. A B C 1 A1 A2 A3 2 B1 B2 B3 3 C1 C2 C3 End product once folders are created should be: Folder 1 (A1 + A2 + A3) Folder 2 (B1 + B2 + B3) Etc... I found multiple formulas on creating folders from single cells but nothing for multiple. I've also tried modifying a few things with no success. Any ideas? Thanks
This comment was minimized by the moderator on the site
Thanks you so much for this helpful post, saved my some time. I love nerds:) What would we do without them, seriously!
This comment was minimized by the moderator on the site
Worked like a charm, but is there a way to create subfolders?
This comment was minimized by the moderator on the site
I'd like to know this too. I nee to make sub folders with given name already added. Example: Excelnamedfolder\P\E I need two folders inside P folder named E and K.
This comment was minimized by the moderator on the site
Trying this on a Mac and I get "Run-time error '68': Device unavailable", and pressing debug points out the following line of code as the culprit: If Len(Dir(ActiveWorkbook.Path & "\" & Rng(r, c), vbDirectory)) = 0 Then MkDir (ActiveWorkbook.Path & "\" & Rng(r, c)) Please help.
This comment was minimized by the moderator on the site
Thanks for this - Excellent time saver
This comment was minimized by the moderator on the site
For some reason the active workbook is having problems with the path. HELPPPP :cry:
This comment was minimized by the moderator on the site
I had a similar issue , at the end I figured it out that program does not work if the file name have slashes / or \ , I replaces / with _, it worked
This comment was minimized by the moderator on the site
You are a lifesaver!!!!! [b]Thank you![b] Note: Don't put a space between MakeFolder and ().
This comment was minimized by the moderator on the site
HELP!!! I Have over 7500 folders to make but the program is having a compiling error highlighting [b]Sub MakeFolders ()[b] as if it is an invalid name or something! I'm operating Excel 2010.
This comment was minimized by the moderator on the site
I had the same problem, but when I looked at the folder name closer there was a / and once I removed it, the code worked like a charm.
This comment was minimized by the moderator on the site
How to do this in LibreOffice or OpenOffice Please reply.
This comment was minimized by the moderator on the site
:-) Thanks for providing this data.... saved my lot of time
This comment was minimized by the moderator on the site
Thanks a lot!!! This is great and most effective and easiest solution I've found on the internet for this! :lol:
This comment was minimized by the moderator on the site
Thanks this save me a lot of time. But how to create sub folders?
This comment was minimized by the moderator on the site
Good... :) Thank you.. It makes me to work simple.
This comment was minimized by the moderator on the site
please, i need that same macro but instead of saving them as folders, i need it to save notepads with only the cell names in a column range, appreciate the support.
This comment was minimized by the moderator on the site
What is the fault in following VBA instruction? Do While r
This comment was minimized by the moderator on the site
Thanks for your reply, the VBA code have little questions when I edit it, so here I have modified it, and it applys successfully, please try it. Good luck!
This comment was minimized by the moderator on the site
SkyYang, [quote]Thanks for your reply, the VBA code have little questions when I edit it, so here I have modified it, and it applys successfully, please try it. Good luck!By skyyang[/quote] YOU ARE AWESOME !! I was able to be more productive at work because of the program (VBA code in Developer).
This comment was minimized by the moderator on the site
Who ever wrote the first example - You are awesome!!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations