vba vlookup 2042

时间:2019-02-15 11:44:48

标签: excel vba

我正在尝试在工作表3上进行vlookup,并且正在从工作表2中获取数据。 因此第二张纸上的数据位于M列,而试图匹配的数据位于第三张纸B列。因此公式应为= VLOOKUP(B2; Lapa6!A:M; 13; false)
我写了这段代码,但始终出现错误2042。


Dim dracct As String
Dim dr24 As Variant
Dim sh1 As Worksheet
Dim sh2 As Worksheet
Dim lastrow As Long
Dim i As Long
Set sh1 = ThisWorkbook.Worksheets(3)
Set sh2 = ThisWorkbook.Worksheets(2)
lastrow = Range("a1000").End(xlUp).Row
For i = 2 To lastrow
dracct = sh1.Cells(i, 2).Value
dr24 = Application.VLookup(dracct, sh2.Range("A:M"), 13, False)
If Not IsError(dr24) Then
sh1.Cells(i, 9).Value = dr24
Else
sh1.Cells(i, 9).Value = n/a
End If
Next i
End Sub

0 个答案:

没有答案