本文介绍了为什么我在VBA比赛中收到错误2042?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有列A:
+--+--------+
| | A |
+--+--------+
| 1|123456 |
|--+--------+
| 2|Order_No|
|--+--------+
| 3| 7 |
+--+--------+
现在如果我输入:
=Match(7,A1:A5,0)
进入表单上的单元格
3
结果。 (这是需要的)
As a result. (This is desired)
但是当我输入这行:
Dim CurrentShipment As Integer
CurrentShipment = 7
CurrentRow = Application.Match(CurrentShipment, Range("A1:A5"), 0)
CurrentRow的值为错误2042
CurrentRow gets a value of "Error 2042"
我的第一个本能是确保值为7实际上在范围内,而且是。
My first instinct was to make sure that the value 7 was in fact in the range, and it was.
我的下一个可能是Match功能需要一个字符串,所以我试过
My next was maybe the Match function required a string so I tried
Dim CurrentShipment As Integer
CurrentShipment = 7
CurrentRow = Application.Match(Cstr(CurrentShipment), Range("A1:A5"), 0)
无效。
推荐答案
尝试这样:
CurrentRow = Application.Match(CLng(CurrentShipment), Range("A1:A5"), 0)
这篇关于为什么我在VBA比赛中收到错误2042?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!