Create folders with excel

Cswift

New Member
Joined
Sep 18, 2023
Messages
5
Office Version
  1. 365
Platform
  1. Windows
Hello,

I am looking for a VBA code that creates a folder from Cell A,B, C as one folder, either in the folder that my Excel sheet is in or changeable.
for Example

Column: A(Name -Last Name, First) C(file #) D(Address
Folder to be created: Name - File # - Address

I also note that i have multiple sheets labeled as months - would i have to create a VBA for each month or can it all be included that one i enter data into A,B,C that a folder gets created.
Is this something that can be done?
Appreciate your help and let me know if i have missed anything.
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
paste this code into a module,
change: kStartDIR = "C:\" to the starting folder you want to use
select the row of the client to make a folder
run: MakeClientFolder

Code:
Sub MakeClientFolder()
Dim vDir
dim iRow as long
Const kStartDIR = "C:\"

iRow = activecell.row
vDir = kStartDIR & Range("A" & iRow ).Value & "-File " & Range("B" & iRow).Value & "-" & Range("D" & iRow).Value
MakeDir vDir
End Sub


Public Sub MakeDir(ByVal pvDir)
Dim fso
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(pvDir) Then fso.CreateFolder pvDir     'MkDir pvDir

Set fso = Nothing
End Sub
 
Upvote 0
This is great! it seems that i have done something incorrect as i see that i have 2023 in front of my folders, what am I doing wrong - i note that my sheet is not in the folder where my folders are being created.
I have attached pictures to hopefully help.
 

Attachments

  • Capture.JPG
    Capture.JPG
    71.8 KB · Views: 12
  • Capture2.JPG
    Capture2.JPG
    20.4 KB · Views: 11
Upvote 0
This is great! it seems that i have done something incorrect as i see that i have 2023 in front of my folders, what am I doing wrong - i note that my sheet is not in the folder where my folders are being created.
I have attached pictures to hopefully help.

Instead of posting pictures, you should post your VBA code.

How to post your code using code tags:
 
Upvote 0
The code is posted above. ? I guess is doesn't stay in the thread when I post?
I do not see any code posted above. We all post code here all the time without issue. Mr. Excel has a test forum where you can practice posting code:

 
Upvote 0
I do not see any code posted above. We all post code here all the time without issue. Mr. Excel has a test forum where you can practice posting code:

There is no issue of me posting the code, my reference was in thought of if it posted above, why would i post it again. From my side i see all posts to my question in a group and if i scroll up the original post with the code that was provided is there.

Code:
Sub MakeClientFolder()
Dim vDir
dim iRow as long
Const kStartDIR = "C:\"

iRow = activecell.row
vDir = kStartDIR & Range("A" & iRow ).Value & "-File " & Range("B" & iRow).Value & "-" & Range("D" & iRow).Value
MakeDir vDir
End Sub


Public Sub MakeDir(ByVal pvDir)
Dim fso
On Error Resume Next
Set fso = CreateObject("Scripting.FileSystemObject")
If Not fso.FolderExists(pvDir) Then fso.CreateFolder pvDir 'MkDir pvDir

Set fso = Nothing
End Sub
 
Upvote 0
There is no issue of me posting the code, my reference was in thought of if it posted above, why would i post it again. From my side i see all posts to my question in a group and if i scroll up the original post with the code that was provided is there.

You did not post code, you posted a GRAPIC IMAGE of your code. Which is what I was referring to in post #4 above. You may consider that to be the same, but from the perspective of anyone trying to help you it is not, since in order to experiment with your code we have to manually type it in to the VBE, instead of simply being able to copy/paste.

The code you just posted looks like it came from @ranman256's post and is not the code you are currently working with. I say this because
what you posted has Const kStartDIR = "C:\" which is different than your image in post #3 which shows it as Const kStartDIR = "C:\Crystal\Real Estate\CLIENTS\2023". That's important because of this question:

This is great! it seems that i have done something incorrect as i see that i have 2023 in front of my folders, what am I doing wrong

You have 2023 in front of your folders because you defined kStartDIR that way. If you want your new folder to be a sub-folder of C:\Crystal\Real Estate\CLIENTS\2023 then you could add a backslash ("\") to the end of kStartDIR:

VBA Code:
Const kStartDIR = "C:\Crystal\Real Estate\CLIENTS\2023\"
 
Upvote 0
You did not post code, you posted a GRAPIC IMAGE of your code. Which is what I was referring to in post #4 above. You may consider that to be the same, but from the perspective of anyone trying to help you it is not, since in order to experiment with your code we have to manually type it in to the VBE, instead of simply being able to copy/paste.

The code you just posted looks like it came from @ranman256's post and is not the code you are currently working with. I say this because
what you posted has Const kStartDIR = "C:\" which is different than your image in post #3 which shows it as Const kStartDIR = "C:\Crystal\Real Estate\CLIENTS\2023". That's important because of this question:



You have 2023 in front of your folders because you defined kStartDIR that way. If you want your new folder to be a sub-folder of C:\Crystal\Real Estate\CLIENTS\2023 then you could add a backslash ("\") to the end of kStartDIR:

VBA Code:
Const kStartDIR = "C:\Crystal\Real Estate\CLIENTS\2023\"
Yes you are correct the code came from that user and yes the kstart was changed as his post stated to change to the folder - maybe I took that too far. :)

i understand that now that i should have pasted the code even though it was at beginning to be more clear.

Really appreciate your help on this!
 
Upvote 0

Forum statistics

Threads
1,215,409
Messages
6,124,737
Members
449,185
Latest member
hopkinsr

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