I can't get this VLookUp formula to apply to my column.
Brief background:
Tab "DATA" has SQL data being pulled in on a refreshed connection.
Tab "Folder" pulls a list of file names from a designated folder; all in Column A.
In the "Folder" tab, Column B, I'd like to add the VLookUp formula, but when I recorded the macro it still will not apply to all the cells only the first cell (B2).
I can find the lastrow, but not sure why the formula isn't apply to every cell. In the For Loop is my feeble attempts at adding the formula in each cell.
Code
Option Explicit
Sub VLookUp()
'
'
Dim lastRow As Long
Worksheets("Folder").Select
lastRow = GetLastRow("A2")
MsgBox ("The last row is " & lastRow)
Dim i As Integer
For i = 2 To lastRow
' Range("B2").Select
' Range("B2" & lastRow).FormulaR1C1 = _
' "=VLOOKUP(Table1[[#This Row],[LoanNumber]],Folder!C[-1],1,FALSE)"
'' Range("B2").Select
'' Selection.AutoFill Destination:=Range("B2:B4")
'Range("B2").FormulaR1C1 = _
' "=VLOOKUP(Table1[[#This Row],[LoanNumber]],"Folder!C[-1] & lastRow",1,FALSE)"
Next i
End Sub
Public Function GetLastRow(incomingRng As String)
GetLastRow = Range(incomingRng).End(xlDown).Row
End Function
Display More