Hi,

I am stucked at this place. I am trying to do vlookup between two workbooks.

I need to do vlookup in column S2 of one workbook.
look value is column Q2
table array is in another workbook (C:\Users\aman.bhardwaj\Desktop\Ideas\Learning process\30th November 2015\AIL RFL\LearnersinMandateDataExport_EMEIA_RFL.xls") - PLEASE CONSIDER THIS WORKBOOK AS OPEN. ALSO IF NOT OPEN THEN CODE HAS TO OPEN IT FROM THE GIVEN LOCATION.

table array in another workbook is - P:Q
column index number - 2

Below is my code. Please help


Sub vlookupRFL()
Dim SourceLastRow As Long
Dim OutputLastRow As Long
Dim sourceBook As Workbook
Dim sourceSheet As Worksheet
Dim outputSheet As Worksheet
 Application.ScreenUpdating = True

'source workbook
Set sourceBook = Workbooks.Open("C:\Users\aman.bhardwaj\Desktop\Ideas\Learning process\30th November 2015\AIL RFL\LearnersinMandateDataExport_EMEIA_RFL.xls")

'names of our worksheets
Set sourceSheet = sourceBook.Worksheets("Sheet1")
Set outputSheet = ThisWorkbook.Worksheets("Sheet1")

'Determine last row of source
With sourceSheet
     SourceLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
End With
With outputSheet

   OutputLastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
   .Range("S2:S" & OutputLastRow).Formula = _
         "=VLOOKUP(Q2,'[" & sourceBook.Name & "]" & sourceSheet.Name & "'!$P2:$Q" & SourceLastRow & ",2,0)"
End With

 Application.ScreenUpdating = True
End Sub