I need some VBA coding help with makefolder()

sagebomb

New Member
Joined
Jan 7, 2019
Messages
1
Hi, I am new the forum and could use some help with some VBA coding. I have an excel file that makes a folder and subfolders when a new entry is made in a cell based upon the cell content. The problem is if the main folder name is modified, the change is not reflected in the excel file and vice versa. I would like to be able to modify the folder name in excel, then the folder in the directory would be updated to reflect the cell content, right now if I change the cell content it just makes a new folder and subfolders. Here is the current VBA code that I am using to create the main folder and subfolders.

Code:
Sub makefolder()
    Dim xdir As String
    Dim fso
    Dim lstrow As Long
    Dim i As Long
    
    Set fso = CreateObject("Scripting.FileSystemObject")
    lstrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
    Application.ScreenUpdating = False
    
    For i = 2 To lstrow
        xdir = "S:\Customer Files\" & Range("C" & i) & Space(1) & Range("E" & i).Value
        If Not fso.FolderExists(xdir) Then fso.CreateFolder (xdir)
        If Not fso.FolderExists(xdir & "\Drawings") Then fso.CreateFolder (xdir & "\Drawings")
        If Not fso.FolderExists(xdir & "\Pictures") Then fso.CreateFolder (xdir & "\Pictures")
        If Not fso.FolderExists(xdir & "\Manuals") Then fso.CreateFolder (xdir & "\Manuals")
        If Not fso.FolderExists(xdir & "\Quotes") Then fso.CreateFolder (xdir & "\Quotes")
        Range("C" & i).Formula = "=HYPERLINK(""" & xdir & """, """ & Range("C" & i).Value & """)"
    Next
    
    Application.ScreenUpdating = True
End Sub

Any help would be greatly appreciated.
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN

Forum statistics

Threads
1,225,739
Messages
6,186,738
Members
453,369
Latest member
juliewar

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