0
m=0
Set fRange = Range("B2:J2")
For Each Cell In fRange
          
        fPath = Cell.Value 
        fName = Cell.Offset(1, 0).Value 
        Application.Workbooks.Open (fPath) 
        Sheets("database").Select
        Cells(m, 2).Select
        ActiveCell.FormulaR1C1 = _
                "=VLOOKUP(RC[-1],[fName]compilation!$H$2:$P$47,2,FALSE)"
       
        m=m+1
        Next Cell

(Normal text) This is my code.I got issue with how i can use the file name as a variable in the vlookup formula. fName used like this give me somme error of syntax. Thanks in advance for any help !

mike_duaud
  • 23
  • 3
  • Thanks a lot. It doesn't work. it still give me error about the syntax. ``` ActiveCell.FormulaR1C1 = "=VLOOKUP(RC[-1],[" & fName & "]compilation!$H$2:$P$47",2,FALSE)" ``` – mike_duaud Aug 12 '22 at 13:23
  • You're also mixing A1 (`$H$2:$P$47`) and R1C1 (`RC[-1]`) notation. It would be best to be consistent. – BigBen Aug 12 '22 at 13:31

0 Answers0