Thread: [Solved] Different suffix per entry
View Single Post
 
Old 04-01-2020, 11:51 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

The following is an example to create the folder structure you described with 5 digit padding and only taking inputs from the part numbers you select before running it. Note that you need to set a Reference to the Microsoft Scripting Runtime.
Code:
Sub MakeFolders()
  'requires reference to Microsoft Scripting Runtime
  Dim subFolders() As String, sPath As String, aCell As Range
  Dim iNum As Long, sCell As String, sFolder As String, i As Integer
  Dim sPathF As String, sPathSubF As String
  Dim fso As New FileSystemObject
  
  sPath = "C:\Temp\"
  subFolders = Split("Calculations|Capacities|Correspondence|Inspections", "|")
  
  For Each aCell In Selection
    sCell = Trim(aCell.Value)
    iNum = Mid(sCell, 3)
    sFolder = "PN" & Format(iNum, "00000")
    sPathF = sPath & sFolder
    If Not fso.FolderExists(sPathF) Then fso.CreateFolder sPathF
    For i = LBound(subFolders) To UBound(subFolders)
      sPathSubF = sPathF & "\" & sFolder & " - " & subFolders(i)
      If Not fso.FolderExists(sPathSubF) Then fso.CreateFolder sPathSubF
    Next i
  Next aCell
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote