I have an excel file which looks up for values from another file. Now I want to change the name of the file which is being used to lookup for values through user input. What I have done is -
Dim fName as String
fName = InputBox("Enter filename")
Range("H2") = "=VLOOKUP(RC[-7],'[fname]Attendance'!R4C7:R283C9,3,0)"
...'similar vlookup lines of code
When I run this I get the inputbox to enter the filename and then the window to browse the filename for every vlookup column keeps on coming. What am I doing wrong?
Edit: I tried doing this but it gives me an error - Application defined or object-defined error
.
fName = Application.GetOpenFilename(, , "Browse for Workbook")
Range("H2") = "=VLOOKUP(RC[-7],'[" & fName & "]Attendance'!R4C7:R283C9,3,0)"
...'similar vlookup lines of code