Thread: Generate Folder
View Single Post
 
Old 07-21-2025, 08:50 PM
Logit Logit is offline Windows 10 Office 2007
Expert
 
Join Date: Jan 2017
Posts: 591
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

Code:
Sub GenerateFoldersFromColumnH()
    Dim ws As Worksheet
    Dim lastRow As Long
    Dim folderName As String
    Dim folderPath As String
    Dim i As Long
    
    ' Set your target worksheet
    Set ws = ThisWorkbook.Sheets("Sheet1") ' Rename if needed
    
    ' Find the last used row in column H
    lastRow = ws.Cells(ws.Rows.Count, "H").End(xlUp).Row
    
    ' Loop through each row in column H
    For i = 2 To lastRow ' Start from row 2 assuming row 1 is a header
        folderName = Trim(ws.Cells(i, "H").Value)
        
        ' Skip blank folder names
        If folderName <> "" Then
            folderPath = " C:\Jobs\" & folderName
            
            ' Check if folder exists
            If Dir(folderPath, vbDirectory) = "" Then
                MkDir folderPath
            Else
                MsgBox "Folder already exists for: " & folderName, vbInformation, "Duplicate Folder"
                Exit Sub
            End If
        End If
    Next i
End Sub
Reply With Quote