Excel VBA ByRef参数类型不匹配 [英] Excel VBA ByRef argument type mismatch
问题描述
我正在尝试编写一个过程,该过程捕获选定单元格时的情况,并仅返回单元格的列和行.我收到"ByRef参数类型不匹配"错误,但这没有任何意义.请参见下面的屏幕截图:
I am trying to write a procedure that captures when a cell has been selected and simply returns the cell column and row. I am getting a 'ByRef argument type mismatch' error but it doesn't make sense. See below screenshot:
问题似乎出在iRow变量上.据我所知,它是一个整数,并且永远不会停止为整数.为什么会发生编译错误?
The issue seems to be with the iRow variable. As far as I can see it is an integer and never ceases to be an integer. Why is the compile error occurring?
请帮助.这让我发疯.
推荐答案
这是因为您已将iRow声明为 Variant
.与VB.Net不同,您将必须显式声明所有变量.任何未声明的内容将作为 Variant
That is because you have declared iRow as Variant
. Unlike VB.Net, you will have to declare all variables explicitly. Anything which is not declared will be taken as a Variant
更改行
Dim iRow, iCol As Integer
到
Dim iRow As Integer, iCol As Integer
这篇关于Excel VBA ByRef参数类型不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!