Hi there! I have 2 questions, but first I will input the code:
Sub automkdir()
Sheets("X").Select
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, "H").End(xlUp).Row
Application.ScreenUpdating = False
For i = 2 To lstrow
'path to create folders
xdir = "C:\Users\blue\Documents\" & Range("H" & i).Value & Left(Range("G" & i).Value, 1)
If Not fso.FolderExists(xdir) Then
fso.CreateFolder (xdir)
End If
Next
Application.ScreenUpdating = True
' Application.OnTime Now + TimeValue("00:01:00"), "automkdir"
End Sub
So this formula works great except for 2 things - It runs on every workbook, I want to limit it just to the workbook and sheet I'm in. I also don't even need it to be running in the foreground and would prefer it just run silently in the background no matter what others worksheets or workbooks I am in, as long as this one is open.
The other problem I have is instead of C:\Users\blue\Documents" I want it to read blue as a variable that I input on lets say Sheet "Y". So if sheet Y has "blue" in Cell A1, and I change is to "red", the macro will look for C:\Users\red\Documents" instead.
Thank you for your help!
Bookmarks