How to match a string wildcard pattern in an excel macro

柔情痞子 提交于 2019-12-25 18:28:01

问题


I have a test like

LEFT('F13',2)='F1'

I want to change it from a left-side match to a test that supports wildcards

'F13'='F?3'

Excel doesn't support regex except in VBA code but i'd prefer this was done in a macro. I should point out that the actual test isn't a simple string, but cell references (this may be important, I'm not sure):

IF(LEFT($DATA.$A$2:$A$1501,LEN($B$3))=$B$3,...

The range actually evaluates to a single cell based on where the macro is called from. $B$3 is the pattern input by the user.


回答1:


=SEARCH("F?3","F13")=1

In your second example, if B3 contains wildcards infused text

=SEARCH(B3,$DATA.$A$2:$A$1501)=1

SEARCH returns the position where it finds the first argument. The "=1" ensures the string starts with the first argument as opposed to somewhere in the middle. I'm not sure how your $DATA argument works, so I just copied it verbatim.



来源:https://stackoverflow.com/questions/1242677/how-to-match-a-string-wildcard-pattern-in-an-excel-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!