vba excel - 找到字符串通配符 [英] vba excel - find string wildcard

查看:935
本文介绍了vba excel - 找到字符串通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个简单的excel搜索引擎,我想制作一些通配符,例如:



我有一个单元格,用户输入搜索项(只有数字)应该是这样的:123456。
然后,我有另一个工作簿,我正在搜索123456。这个我设法做了。



然而,我该如何制作通配符?例如,我希望用户能够搜索:123?56,我会给他的结果如下:123456,123356,123556等。



这是我如何查找完全匹配:

  set rFound = wks.UserRange.Find(strToSearch ,LookIn:= xlValues,lookat:= xlwhole,MatchCase:= False)

任何想法? p>

谢谢

解决方案

您可以在循环中使用通配符与查找

  Sub dural2()
MsgBox范围(A1:A10)。Find(What:=123 * 56,After:= Range(A1))Row
End Sub
pre>



或在$ code>像:

  Sub dural()
对于每个r In范围(A1:A10)
如果r.Value喜欢123 * 5 6然后
MsgBox r.Address
结束如果
下一步r
结束Sub


I am doing a simple search engine in excel and I want to make some wildcards, for example:

I have a cell where the user input the search term (only numbers) which should look like this: "123456". then, I have another workbook, where I search for the "123456" exactly. this I managed to do.

however, how can I make wildcards? for example, I want the user to be able to search for: "123?56" and I will give him the results of: "123456", "123356", "123556" etc.

this is how I look for the exact match:

set rFound = wks.UserRange.Find(strToSearch, LookIn:=xlValues, lookat:=xlwhole, MatchCase:=False)

any ideas?

thank you

解决方案

You can use a wildcard either in a loop or with Find:

Sub dural2()
    MsgBox Range("A1:A10").Find(What:="123*56", After:=Range("A1")).Row
End Sub

or in a loop with Like:

Sub dural()
    For Each r In Range("A1:A10")
        If r.Value Like "123*56" Then
            MsgBox r.Address
        End If
    Next r
End Sub

这篇关于vba excel - 找到字符串通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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