我想自动运行以下声明:
= VLOOKUP(B8,Sheet 2中d:H,5,FALSE)
但我在第6行遇到错误:无法获取WorksheetFunction类的VLookup属性
Sub Test()
Dim rng As Range
Dim i As Long
With ActiveSheet
Set rng = .Range("B8:D" & .Cells(.Rows.Count, 1).End(xlUp).Row)
For i = 18 to rng.Rows.Count
rng.Cells(8, 6) =
Application.WorksheetFunction.VLookup(.Cells(i,1), Sheets("Sheet2").Range("D:H"), 5, False)
Next
End With
End Sub
我希望通过查找Sheet2
将输出放在SheetT F8上答案 0 :(得分:0)
我怀疑你想要
Sub Test()
Dim i As Long
With ActiveSheet
For i = 8 to .Cells(.Rows.Count, "B").End(xlUp).Row
.Cells(i, "F").Value = Application.VLookup(.Cells(i, "B").Value, _
Sheets("Sheet2").Range("D:H"), _
5, _
False)
Next
End With
End Sub
您的原始代码是:
rng.Cells(8, 6)
,这是一个B8
偏移7行5列的单元格,即G15
(或早期版本中的C15
)< / LI>
ActiveSheet.Cells(i, 1)
作为查找值,这是A列中的单元格