匹配功能? VBA无法正常工作 [英] Match function? VBA not working properly

查看:123
本文介绍了匹配功能? VBA无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个下面的代码,并且在单元格B11,B19和B25中有名称,我期待的结果是19或25代码,但它返回Y = 1。任何人都可以告诉我是什么问题。

I have a following code and i have "name" in cells B11 , B19 and B25 and i was expecting a result of 19 or 25 with the code but it returns Y=1. Could anyone tell me what is the problem?.

Sub mat()

Y = Application.Match("name", ActiveSheet.Range("B19:B30"), 0)
MsgBox Y

End Sub


推荐答案

根据 MATCH文档 b
$ b

According to the documentation for MATCH:


MATCH返回匹配值在lookup_array中的位置,而不是价值本身。

MATCH returns the position of the matched value within lookup_array, not the value itself.

0 作为可选的第三个参数( match_type ):

and with 0as the optional third argument (match_type):


如果match_type为0,MATCH将查找与lookup_value完全相同的第一个值。 Lookup_array可以以任何顺序。

所以返回的 1 引用 B19 在数组范围内(B19:B30)并且代码示例的行为确实如预期。

So the returned 1refers to the position on B19in the array Range("B19:B30") and the code sample is indeed behaving as expected.

这篇关于匹配功能? VBA无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆