How do you writing a VBA function for vlookup?I tried the following but it doesn't work. Can anyone spot the what is wrong?
Sub fx_vba_test()
Set startcell = Application.InputBox(prompt:="Please select cell", Type:=8)
startcell.CurrentRegion.Select
Dim i As Integer
For i = 1 To startcell.CurrentRegion.Rows.Count
startcell.Cells(i, 11).FormulaR1C1 = Right(startcell.Cells(i, 3), 3)
startcell.Cells(i, 12).FormulaR1C1 = Left(startcell.Cells(i, 3), 3)
startcell.Cells(i, 14).FormulaR1C1 = Application.WorksheetFunction.vlookup(startcell.Cells(i, 12), Windows("acfx").Worksheets("sheet1").Columns("A:B"), 2, False)
startcell.Cells(i, 15).FormulaR1C1 = startcell.Cells(i, 13) / startcell.Cells(i, 14)
startcell.Cells(i, 18).FormulaR1C1 = startcell.Cells(i, 17)
startcell.Cells(i, 20).FormulaR1C1 = startcell.Cells(i, 18) - startcell.Cells(i, 15)
Next
End Sub
Bookmarks