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:
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.
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
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
r = r + 1
3. Click 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:
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.
1. Click Kutools Plus > Import/Export > Filename List.
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="https://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.
The Best Office Productivity Tools
Kutools for Excel Solves Most of Your Problems, and Increases Your Productivity by 80%
Reuse: Quickly insert complex formulas, charts and anything that you have used before; Encrypt Cells with password; Create Mailing List and send emails...
Super Formula Bar (easily edit multiple lines of text and formula); Reading Layout (easily read and edit large numbers of cells); Paste to Filtered Range...
Select Duplicate or Unique Rows; Select Blank Rows (all cells are empty); Super Find and Fuzzy Find in Many Workbooks; Random Select...
Exact Copy Multiple Cells without changing formula reference; Auto Create References to Multiple Sheets; Insert Bullets, Check Boxes and more...
Extract Text, Add Text, Remove by Position, Remove Space; Create and Print Paging Subtotals; Convert Between Cells Content and Comments...
Super Filter (save and apply filter schemes to other sheets); Advanced Sort by month/week/day, frequency and more; Special Filter by bold, italic...
Combine Workbooks and WorkSheets; Merge Tables based on key columns; Split Data into Multiple Sheets; Batch Convert xls, xlsx and PDF...
More than 300 powerful features. Supports Office/Excel
2007-2019 and 365. Supports all languages. Easy deploying in your enterprise or organization. Full features
30-day free trial. 60-day money back guarantee.
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
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.
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?
SkyYang, [quote name="skyyang"]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![/quote] YOU ARE AWESOME !! I was able to be more productive at work because of the program (VBA code in Developer).