Try the below code, in this, it will run for "X" sheet only, since the third line of code is activating that sheet only
Sub automkdir()
VarUserName = Worksheets("Y").Cells(1, 1).Value
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
ActiveSheet.Range("H2:H" & lstrow).Select ' Limiting the selection to ActiveSheet
For Each Cell In Selection
'path to create folders
xdir = "C:\Users\" & VarUserName & "\Documents\" & Cell.Value & Left(Cell.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
Bookmarks