I have to insert the VLOOKUP formula to sum up specific columns from the newest file in a folder.
To get the newest file I used: outfilepath=Directory.GetFiles(FolderPath,"*.xlsx”,SearchOption.AllDirectories).OrderByDescending(Function(d) New FileInfo(d).CreationTime)(0)
Then I wrote the formula into a txt file and replaced the field < C1>, C2 with the cells I need. =IFERROR(VLOOKUP($B< C1>,‘< C3>’!$A:$N,< C2>$2,0),0)
I replaced C3 with outfilepath to insert the newest file path.
Until now the formula in excel looks like this: =IFERROR(VLOOKUP($B4;‘C:\Users\admin\Box[Test file WK 35.xlsx]’!$A:$N;G$2;0);0)
But to get the data I need I, the formula also needs the sheetname (“output”)
But if I just insert the word “Output” right after the < C3> in the txt then the formula looks like this in Excel:
Okey.
In that case
1.Try to get full file path using Path.GetFullPath(file) method and store it in variable X.
2.Replace Path.GetFileName(file) with “[”+Path.GetFileName(file)+“]” in X variable