Application.VLookup的错误2042

时间:2018-04-11 19:09:54

标签: vba excel-vba excel

我正在尝试在另一张表中查找单元格值。当我使用以下代码时,debug.print的输出为Error 2042。如果我用“39875”这样的静态值替换Cells(i, store).Value,它就可以完美运行。

With Sheets("250")
    numCol = .Cells(1, .Columns.Count).End(xlToLeft).Column
End With

numRows = Range("A1", Range("A1").End(xlDown)).Rows.Count
Dim store
Dim agType
For i = 1 To numCol
    If Trim(Cells(1, i).Value) = "Balancing Seg" Then store = i
    If Trim(Cells(1, i).Value) = "Ag Type" Then agType = i
Next

Sheets("Worksheet").Activate
For i = numRows To 1 Step -1
    With Worksheets("250")
        x = Application.VLookup(Cells(i, store).Value, .Range("A1:I" & .Range("A1", .Range("A1").End(xlDown)).Rows.Count), 9, False)
    End With
    Debug.Print (x)
Next

我是否对VLookup的第一个参数做错了什么?

0 个答案:

没有答案