Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

vba excel - find string wildcard

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

enter image description here

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...