As yet stated according to your 'File structure' list only 2 files can be treated so you must first correct this list …
On my side the Dir VBA function can not work 'cause of the asian characters in some files names so according to your attachment :
PHP Code:
Sub Demo1()
Dim P, F$, oF As Object, V
With Sheet1
P = .[TRANSPOSE(B2:B3&IF(RIGHT(B2:B3,1)<>"\","\",""))]
With .Range("A8", .[B7].End(xlDown)).Columns
F = "TRANSPOSE(IF(ISNUMBER(MATCH(" & .Item(1).Address(, , , True) & ",{""#""},0))," & .Item(2).Address(, , , True) & "))"
End With
End With
With CreateObject("Scripting.FileSystemObject")
If .FolderExists(P(1)) And .FolderExists(P(2)) Then
Application.DisplayAlerts = False: Application.ScreenUpdating = False
For Each oF In .GetFolder(P(1)).Files
V = Filter(Evaluate(Replace(F, "#", oF.Name)), False, False)
If UBound(V) = 0 Then
With Workbooks.Open(oF.Path, , , , V(0))
.SaveAs P(2) & Left(oF.Name, InStrRev(oF.Name, ".")) & "xlsx", 51, Empty
.Close
End With
End If
Next
Application.DisplayAlerts = True: Application.ScreenUpdating = True
Else
Beep
End If
End With
End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon « ★ Add Reputation » ! ◄ ◄
Last edited by Marc L; 06-13-2021 at 06:57 AM.
Reason: tiny optimization …
Bookmarks