create folders with a file in it

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,443
Office Version
  1. 365
Platform
  1. Windows
I have a list of names and the code number in column A1 to B10. sometimes, less than 10 names are also there.

e.g.:
John254689
James245682
Alisha458213

How can have a folder created with these names and codes.
Folders should look like this
John - 254689
James - 245682 ...

There is a file saved in a particular folder, this file should be copied and pasted in each of the new folder that gets created.
Please assist.
 

snjpverma

Well-known Member
Joined
Oct 2, 2008
Messages
1,443
Office Version
  1. 365
Platform
  1. Windows
In the above code before for...next loop

VBA Code:
    Dim strFile As String
    strFile = "D:\Test VBA\000.xlsx"    ' modify this one
  
    Dim fso As Object
    Set fso = CreateObject("Scripting.FileSystemObject")
  
    Dim oFile As Object
    Set oFile = fso.GetFile(strFile)

Inside the for...next loop right before "Next":

VBA Code:
    If not fso.FileExists(fso.BuildPath(c00, oFile.Name)) Then oFile.Copy fso.BuildPath(c00, oFile.Name)

Right before "End Sub"

VBA Code:
    Set oFile = Nothing
    Set fso = Nothing
this works fine. thank you
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.

Forum statistics

Threads
1,147,455
Messages
5,741,218
Members
423,649
Latest member
steel1968

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
Top