VBA中的Application.match [英] Application.match in VBA

查看:677
本文介绍了VBA中的Application.match的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用"Application.match"来查找工作表的列AD是否包含"1".

I'm using "Application.match" to find if Column AD of a sheet contains "1".

但是,每当我尝试运行代码时,"Else"条件始终为True.尽管我希望它会进入"If"条件,因为Column AD的单元格值为"1".

But whenever I try to run my code, "Else" condition is always True. Although I'm expecting it to enter the "If" condition, since Column AD has a cell with a value "1".

AD列中单元格的值大部分是公式的结果,除了AD1(具有字符串"Titile& Author Match")和AD2(具有值"0")之外.

The values of the cells in Column AD are mostly results of a formula, except for AD1, which has the string "Check if Titile&Author Match", and AD2, which has the value "0".

出了什么问题.有什么解决方案?

What is the problem. What is the solution for it?

我希望您可以建议仍然使用".match"方法的解决方案.这是因为根据我的理解,.match"方法返回范围内匹配的相对位置.而且我计划稍后在代码中使用该值.

I hope you can suggest a solution that would still use the ".match" method. This is because from my understanding ".match" method returns the relative position of the match in the range. And I plan to use that value later on in my code.

Private Sub CmdLocateDta_Click()

Dim SearchColumn As Integer

If Not IsError(Application.Match(1, "AD:AD", 0)) Then
    SearchColumn = Application.Match(1, "AD", 0)
    MsgBox "Data has been located." & vbNewLine & _
           "You can now input the Lending Information below."
Else
    MsgBox "There seems to be no such book in the Database." & _
            vbNewLine & "Please re-check your input."
End If

End Sub

推荐答案

您需要指定两个匹配项中搜索的范围.

You need to specify the range where to search in both Matches.

Application.Match(1, ws.range("AD:AD"),0)

其中ws是您的工作表.

where ws is your worksheet.

这篇关于VBA中的Application.match的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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