VBA to create folder, subfolder and save workbook

aaaaa34

Board Regular
Joined
Feb 25, 2014
Messages
62
Hello my friends,
I have a file mainlist.xlsx in my folder C:\Database
Inside this mainlist.xlsx file, there is list of cars.
in A column car brandname, B column: model name, C column model year, D column motor volume and E column price
In this manner, I want to have VBA to create folder with a name of A-column Brandname and subfolder B-column Model name
Example:
A1 Peugeot
B1 208
then folder and subfolder should be like this C:\Database\Peugeot\208 and save these rows regarding 208 model as a new workbook 208.xlsx
Please download attached file in the link below and you will see mainlist.xlsx with folders, subfolders and new workbooks inside them.
https://jumpshare.com/v/piJgKwBafKflHGfwQPiy
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
No error handling is included...

Code:
Sub MakeDirectories()
CntRows = Range("A1").CurrentRegion.Rows.Count

For C = 1 To CntRows
SubA = Range("A" & C).Value
SubB = Range("B" & C).Value

MKString = "C:\Database\" & SubA & "\" & SubB
MK1String = "C:\Database\" & SubA

MkDir MK1String
MkDir MKString

Next C
End Sub
 
Upvote 0
I am not able to open your links from my current location.
 
Upvote 0

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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