在VBA Excel宏中关闭文件的Vlookup

时间:2014-09-16 12:39:48

标签: excel vba excel-vba

我有一个宏,在几行中需要在一个单独的文件中VLOOKUP一个值。

我提出了代码:

     temp = Left(Cells(row, 5), 10)
     temp2 = "VLOOKUP(" & temp & ";'F:\folder\[file.xlsx]Worksheet1'!$A:$B;2;0)"

     Cells(row, 7).Formula = temp2
     Cells(row, 7).Replace "VLOOKUP", "=VLOOKUP"

IT确实vlookup很好,但仅限于第一行 - 如果我把它放入循环中,那么所有其他行都会得到"公式错误"消息框。

1 个答案:

答案 0 :(得分:0)

好吧,现在我记得我有类似的问题。在公式中的VBA代码中,您必须使用逗号而不是分号:

Cells(row, 7).Formula = "=VLOOKUP(Left(" & Cells(row, 5).Address & ", 10), 'F:\folder[file.xlsx]Worksheet1'!$A:$B,2,0)"