Home » excel » excel vba – How to implement dynamic VLOOKUP in VBA?

excel vba – How to implement dynamic VLOOKUP in VBA?

Posted by: admin May 14, 2020 Leave a comment

Questions:

I am trying to write a VBA function which will insert a dynamic vlookup command to the entire column (column “E”). My goal is to copy data from another sheet (called “WBTS”). Unfortunately, the syntax seems to be illegal. ‘LastRow’ represents the ultimate occupied row in that column.

For X = 2 To LastRow2
Cells(X, 5).Value = "=VLOOKUP(D"&X",WBTS!$D$2:$I$466,6,FALSE)"
Next X
How to&Answers:

Try this

Cells(X, 5).formula = "=VLOOKUP(D" & X & ",WBTS!$D$2:$I$466,6,FALSE)"