Creating Directories from data in selected cell and then create a sub-directory, one Macro

ozzborn

Board Regular
Joined
Sep 14, 2011
Messages
84
Office Version
  1. 365
  2. 2019
  3. 2016
Platform
  1. Windows
I am trying to create a Macro in VBA editor. What I want it to do is create a directory from the text in one cell be selected.

The code below works to create the directory from a selected cell but will not create sub-directory called "High".

I also think I need some error handling included... I am not very good at VBA.

Sub MakeDirs()
For Each cell In Selection
MkDir "C:\Users\Owner\Documents\Mainfolder" & cell.Value
MkDir "C:\Users\Owner\Documents\Mainfolder" & cell.value & "\High"
Next cell
End Sub

Any help is greatly appreciated.

Thanks
Ozz
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Depending on what your cell values are, you might need to make this change
Code:
Sub MakeDirs() 
For Each cell In Selection 
   MkDir "C:\Users\Owner\Documents\Mainfolder\" & cell.Value
   MkDir "C:\Users\Owner\Documents\Mainfolder\" & cell.value & "\High"
Next cell 
End Sub
 
Upvote 0
That worked, thank you.

I thought I had tried that at least it was in my notes.

Thanks again.

Ozz
 
Upvote 0
Glad to help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,557
Members
449,088
Latest member
davidcom

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top