Vlookup代码填充相同的值。如何获得正确的价值
来源是
ADSU01A 15.14166667
ADSU01B 13.41944444
ADSU01C 12.21111111
ADSU01D 8.64
显示Vlookup值
ADSU01A 15.14166667
ADSU01B 15.14166667
ADSU01C 15.14166667
ADSU01D 15.14166667
使用的代码是:
lastrow = Sheet1.Range("B" & Rows.Count).End(xlUp).row
Set Mytable = Range("A:G")
For i = 2 To lastrow
Cells(i, 12) = Application.WorksheetFunction.VLookup(Cells(i, 1), _
Range("Mytable"), 3, False)
Next i
答案 0 :(得分:0)
下面的代码对我来说在图像中的布局很好。
Sub vlookupadd()
Dim WB As Workbook
Dim ws As Worksheet
Set WB = ActiveWorkbook
Set ws = WB.ActiveSheet
lastrow = ws.Range("B" & Rows.Count).End(xlUp).Row
Set mytable = ws.Range("A:G")
For i = 2 To lastrow
ws.Cells(i, 12) = Application.WorksheetFunction.VLookup(ws.Cells(i, 11), mytable, 2, False)
Next i
End Sub