宏查找多个条件类型不匹配错误



>我正在研究一个Excel VBA宏,它从另一个工作表获取响应的id。

我从VLookup收到错误13"类型不匹配":

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:DMexcel_filesjobs.xlsx")
Set extwbk = Workbooks.Open("C:DMexcel_filesRefRes.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

任何帮助表示赞赏!

错误是由以下行引起的:

.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的结果返回到求和中使用的列中。

最新更新