我正在尝试使用索引/匹配组合从定义的表“ tblPlant1”中引入一个值。问题出在Match函数的“错误2015”和Index函数的问题之间。我最终希望将匹配结果合并到索引函数中。我了解错误2015的<255限制,但是很难理解它是如何基于查找值和查找数组得出错误的。代码,Debug.Print输出和表格如下。预先感谢。
Dim plantcode As String
Dim tblPlant1 As ListObject
Dim matchresult As Variant
Dim errormsg As String
Dim VIN As String
Dim Plant1 As Variant
Set tblPlant1 = ThisWorkbook.Sheets(1).ListObjects("tblPlant1")
VIN = ActiveCell.Value
plantcode = Mid(VIN, 11, 1)
errormsg = "Error: Plant Code " & Chr(34) & plantcode & Chr(34) & " (VIN Digit 11) Not Found"
matchresult = Application.Match(plantcode, tblPlant1.ListColumns("VIN"), 0)
Plant1 = WorksheetFunction.IfError(Application.Index(tblPlant1.ListColumns("Plant"), 6), errormsg)
Debug.Print errormsg
Debug.Print VIN
Debug.Print plantcode
Debug.Print matchresult
Debug.Print Plant1
调试的输出如下:
错误:找不到工厂代码“ H”(VIN数字11)
1HTKSSWK9KH067162
H
错误2015
错误:找不到工厂代码“ H”(VIN数字11)