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

Popular Features: Find, Highlight or 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  |  Toggle Visibility Status of Hidden Columns  |  Compare Ranges & Columns ...
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 Toolsets12 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, ...)   |   ... and more

Supercharge Your Excel Skills with Kutools for Excel, and Experience Efficiency Like Never Before. Kutools for Excel Offers Over 300 Advanced Features to Boost Productivity and Save Time.  Click Here to Get The Feature You Need The Most...

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
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations