VLookup循环无法正常工作

时间:2015-10-06 06:11:10

标签: vba excel-vba vlookup excel

我尝试了VLookup,直到A列中的单元格为空并且它不能正常运行并返回运行时错误' 1004'无法获取WorksheetFunction类的VLookup属性。有帮助吗?或者是否有更好的循环我可以使用。

Sub FindOldValue()
Dim oldvalue As String
Dim result As String
i = 2
j = 1
K = 2
l = 3

Do

oldvalue = Worksheets("Products").Cells(i, j) & Worksheets("Products").Cells(i, K) & "delete"
result = Application.WorksheetFunction.VLookup(oldvalue, Worksheets("Raw Delta").Range("A:H"), 7, 0)
Worksheets("Products").Cells(i, l) = result
i = i + 1
j = j + 1
K = K + 1

Loop Until Worksheets("Products").Cells(i, 1) = ""

End Sub

1 个答案:

答案 0 :(得分:1)

您是否尝试过在行中仅使用Application.Vlookup而不是Application.Worksheetfunction.vlookup

result = Application.WorksheetFunction.VLookup(oldvalue, Worksheets("Raw Delta").Range("A:H"), 7, 0)

如何将循环更改为这样的东西?

Do

oldvalue = Worksheets("Products").Cells(i, j) & Worksheets("Products").Cells(i, K) & "delete"
resultrow = Application.Match(oldvalue, Worksheets("Raw Delta").Columns(1), 0)
If Not IsError(resultrow) Then
    Worksheets("Products").Cells(i, l) = Worksheets("Raw Delta").Cells(resultrow,7).Value
End If
i = i + 1
j = j + 1
K = K + 1

Loop Until Worksheets("Products").Cells(i, 1) = ""