I am a newbie in excel macro vba. I have a problem on my vlookup code which refers to another workbook selected by a user.
Here's my code:
Private Sub vlookups()
Dim data_file_new As String
Dim i As Integer
Dim a As String, b As String, path As String
data_file_new = CStr(Application.GetOpenFilename(FileFilter:="Excel Workbooks (*.xls*),*.xls*", Title:="Select new data file for VLOOKUP"))
path = data_file_new
a = "=VLOOKUP(A:A,'[" & path & "]Source'!$A:$AB,28,0)"
b = "=VLOOKUP(A:A,'[" & path & "]Source'!$A:$AJ,36,0)"
i = 7
Do Until Sheets("Macro Template").Cells(i, 1) = ""
Sheets("Macro Template").Cells(i, 37) = a
Sheets("Macro Template").Cells(i, 38) = b
i = i + 1
Loop
End Sub
My problem is that my code doesn't give the correct formula for the vlookup. instead, it gives this formula:
=VLOOKUP(A:A,'[E:\AP NO APPROVAL\[No Approval Monitoring Log_June 2015 xlsx.xlsx]Source]No Approval Monitoring Log_June'!$A:$AB,28,0)
the correct formula is this:
=VLOOKUP(A:A,'E:\AP NO APPROVAL\[No Approval Monitoring Log_June 2015 xlsx.xlsx]Source'!$A:$AB,28,0)
Any help would be appreciated.
Thanks!
path
? Try putting a breakpoint on the line where you assign a value topath
and see what value of it is. Sounds like it has the incorrect value in it – Martin"=VLOOKUP(A:A,'["
should be"=VLOOKUP(A:A,'"
Secondly. I am wondering how are you getting the first formula. Your first formula should be ending in]Source'!$A:$AB,28,0)
Can you recheck that for me? – Siddharth Rout