vba中的Vlookup循环,如何调试?

时间:2019-04-07 10:42:23

标签: excel vba vlookup

我有一堆工作表名称从1到200(例如)的工作表,我想创建一个概览。我在vba中以循环形式使用了vlookup函数。但是有一个我无法理解的错误。

Sub Loop_Vlookup()
    Dim for_col As Long, i As Long, r As Long, c As Long, column As Long, ws As Long
    r = 3: c = 7: column = 2

    For for_col = 1 To Range("XFD2").End(xlToLeft).column - 6    
        ws = ActiveWorkbook.Sheets.Count - 2
        For i = 1 To ws
           Cells(r, c).Value = ActiveWorkbook.Application.WorksheetFunction.VLookup(Cells(1, c).Value, ActiveWorkbook.Sheets(i).Range("A:B"), column, 0)
           r = r + 1          
        Next
        r = 3
        c = c + 1    
    Next    
End Sub

我得到了这个“无法获取工作表函数类的vlookup属性”。我不知道原因。

1 个答案:

答案 0 :(得分:2)

您可以使用WorksheetFunction.Vlookup代替Application.Vlookup

How to error handle 1004 Error with WorksheetFunction.VLookup?