I'm not yet on VBA coding so I need your help for speeding up my work. Basically this is what I need:
Column A (what I provide): list of file
Column B (what I'm looking for): Path of file
Can you give me any advice? I think that should be a simple code but I don't know yet how to start. Thank you in advance.
Regards, Andrea
Here's more information...
Input:
1234XX12345_Sheet3_2
Output:
1234XX12345_Sheet1_2
1234XX12345_Sheet2_2
1234XX12345_Sheet3_2
While it "expand" the number of sheet i'd like to search for it in a directory and write the path. I hope it's clear enough ^^'
Public Function LastRow(colonna As String) As Long
LastRow = ActiveSheet.Cells(Rows.Count, colonna).End(xlUp).Row
End Function
Public Function LastCol(riga As Integer) As Long
LastCol = ActiveSheet.Cells(riga, Columns.Count).End(xlToLeft).Column
End Function
Public Function Recurse(sPath As String) As String
Dim FSO As New FileSystemObject
Dim myFolder As Folder
Dim mySubFolder As Folder
Dim myFile As File
Set myFolder = FSO.GetFolder(sPath)
For Each mySubFolder In myFolder.SubFolders
For Each myFile In mySubFolder.Files
If myFile.Name = Range(Foglio1.Cells(ultimax, 2)).Value Then
Foglio1.Cells(ultimax, 3) = myFile.Path
Exit For
End If
Next
Recurse = Recurse(mySubFolder.Path)
Next
End Function
And command Box:
Private Sub CommandButton1_Click()
Dim ultimax As Long
Dim n_sheet As Integer
Dim iso As String
Foglio1.Range("B2:B1000000").Clear
ultimax = 2
For i = 2 To LastRow("A")
a = Split(Foglio1.Cells(i, 1), "_")
n_sheet = Replace(a(1), "Sheet", "") * 1
For j = 1 To n_sheet
Foglio1.Cells(ultimax, 2) = a(0) & "_" & Left(a(1), 5) & j & "_" & a(2) & ".pdf"
Call Recurse("C:\Users\VVVVV\Desktop\TEST_VB")
ultimax = ultimax + 1
Next j
Next i
MsgBox "FINISH!!"
End Sub