我正在开发一个Excel VBA宏,它从另一张表中获取响应的ID。
我收到错误13"输入错误"来自VLookup:
Dim i As Integer
Dim LastRow As Integer
Dim LastColumn As Integer
Dim rw As Long, x As Range, x1 As Range
Dim extwbk As Workbook, twb As Workbook
Sub Job_Res()
LastRow = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
'----------SET RES ID-----------------------------
Set twb = Workbooks.Open("C:\DM\excel_files\jobs.xlsx")
Set extwbk = Workbooks.Open("C:\DM\excel_files\RefRes.xlsx")
Set x = extwbk.Worksheets("Sheet1").Range("A:D")
With twb.Sheets("Sheet1")
MsgBox "OK"
For rw = 2 To .Cells(Rows.Count, 1).End(xlUp).Row
.Cells(rw, 11) = Application.VLookup(.Cells(rw, 11).Value + .Cells(rw, 1).Value, x, 2, False)
Next rw
End With
extwbk.Close savechanges:=False
End Sub
任何帮助表示赞赏!
答案 0 :(得分:0)
错误是由此行引起的:
.Cells(rw, 11) = Application.VLookup(.Cells(rw, 11).Value + .Cells(rw, 1).Value, x, 2, False)
我的猜测是问题在Arg1中 - 求和.Cells(rw, 11).Value + .Cells(rw, 1).Value
无法正确执行。我不知道您是否要添加文本值(例如“a”+“a”)或数值(1 + 1)。但是如果你添加文字和数字(1 +“a”),它将返回错误
此外,您将Vlookup的结果返回到求和中使用的列。