vba - 在循环中查找

时间:2015-08-05 07:16:49

标签: vba foreach vlookup

我尝试为每个单元格执行vLookup,但它似乎不起作用

Sub Extern()

    Dim WS_Count As Integer
    Dim I As Integer
    Dim c As Integer
    Dim j As Range
    Dim e As Range

    lRow = Worksheets("Übersicht").Range("A65536").End(xlUp).Row
    WS_Count = ActiveWorkbook.Worksheets.Count
    c = 41

    For Each j In Worksheets("Übersicht").Range("A41:A" & lRow)

        Set Rng = Worksheets("Übersicht").Range("B" & c)

        For I = 3 To WS_Count
            If Worksheets(I).Name Like "*uslastu*" Then

                Rng.Formula = "=VLOOKUP(j,Worksheets(I)!B:C,2)"

            End If
        Next I

        c = c + 1
    Next j
End Sub

如果您发现任何错误,请提供帮助。当我尝试调试它时,它表示Lookup公式,是问题。

1 个答案:

答案 0 :(得分:0)

因为你将变量j和I放在标记“”中,因此VBA理解它是文本,并且不会将任何值传递给这些变量。结果,您的公式将是错误。

您可以尝试以下公式:

"=VLOOKUP(" & j.Address & "," & Worksheets(I).Name & "!B:C,2,0)"