This post will guide you how to create folders based on cell values in the current worksheet in Excel. How do I automatically create folders based on cell values with VBA macro in Excel. How to use VBA macro to create folders bsed on cell values in Excel.
Create Folders based on Cell Values
Assuming that you have cell values in range of cells B1:B6, and you want to create folders based on those cell values in the current workbook directory. How to quickly achive the result. You can create an Excel VBA macro to quickly create folders based on the selected cell values. Just do the following steps:
#1 open your excel workbook and then click on “Visual Basic” command under DEVELOPER Tab, or just press “ALT+F11” shortcut.
#2 then the “Visual Basic Editor” window will appear.
#3 click “Insert” ->”Module” to create a new module.
#4 paste the below VBA code into the code window. Then clicking “Save” button.
Sub MakeFolders() Dim dirName as string on error resume next For i=1 to 6 dirName=cells(1,i).values mkdir (ActiveWorkbook.Path & "\" & dirName) next i End Sub
#5 back to the current worksheet, then run the above excel macro. Click Run button.
The folders have been created under the current spreadsheet active directory.
Leave a Reply
You must be logged in to post a comment.