[英]Why am I getting a" Run time Error '13': Type Mismatch" error message?
我对 VBA 很陌生,仍在学习编程语言和编码。 在参考了几个在线教程和线程后,我为我的项目想出了以下代码。 当我运行代码时,我收到一条错误消息,说,运行时错误:类型不匹配。如果你们中的任何一位专家可以帮助我找到错误,我们将不胜感激。
非常感谢提前
Dim wsServiceRegistry As Worksheet, wsInhouseMaterialInventory As Worksheet
Dim updateCell As Range
Dim emptyRow As Long
With ThisWorkbook
Set wsServiceRegistry = .Worksheets("Service Registry")
Set wsInhouseMaterialInventory = .Worksheets("Inhouse Material Inventory")
End With
Set updateCell = wsInhouseMaterialInventory.Cells(Me.InhouseMaterialComboBox.ListIndex + 2, 4)
updateCell.Value = updateCell.Value - Val(Me.MaterialQuantityTextBox.Value)
If updateCell.Value < 1 Then updateCell.EntireRow.Delete: Exit Sub
唯一可能导致类型不匹配的行是
updateCell.Value = updateCell.Value - Val(Me.MaterialQuantityTextBox.Value)
,取决于单元格包含的内容。
首先要找出它是否是您真正想要的单元格,以及它是否包含您期望的内容。 在相关行的正上方添加这些行:
Debug.Print updateCell.Address
Debug.Print updateCell.Value
按Ctrl + G显示调试输出并运行它。 如果输出符合您的期望,那么您将不得不再次使用Val
函数,如下所示:
updateCell.Value = Val(updateCell.Value) - Val(Me.MaterialQuantityTextBox.Value)
强制updateCell
成为您可以从中减去的东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.