excel - 如何解决索引/匹配返回错误的问题?
问题描述
我正在尝试使用索引/匹配组合从定义的表“tblPlant1”中引入一个值。问题在于 Match 函数的“错误 2015”和 Index 函数的问题。我最终想将匹配结果合并到 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)
解决方案
推荐阅读
- .net - .net mvc,为用户设置角色来自outlook
- python - 当应用在没有 for 循环的情况下无法工作时,如何迭代 DataFrame?
- google-chrome - 量角器 woant 运行我的脚本
- html - 在 Amazon S3 上显示 em-dash
- javascript - 即使目标是支持 ES 模块的现代浏览器,是否需要打包程序?
- ionic3 - 更改离子列表项单击时的复选框状态?
- bash - 从 VS Code 中提取 OUTLINE(或 AL OUTLINE)的内容
- javascript - 金额字段的Javascript正则表达式(不允许小数点后零以外的数字)
- django - Django 模型:两个字段的乘法
- mysql - 查询每年销售额超过平均销售额的业务员列表