如何在excel宏中匹配字符串通配符模式
我有一个类似的测试
LEFT('F13',2)='F1'
我想把它从左侧匹配改为支持通配符的测试
I want to change it from a left-side match to a test that supports wildcards
'F13'='F?3'
Excel 不支持正则表达式,除了在 VBA 代码中,但我更喜欢这是在宏中完成的.我应该指出,实际测试不是一个简单的字符串,而是单元格引用(这可能很重要,我不确定):
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,...
范围实际上根据调用宏的位置计算为单个单元格.$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.
=SEARCH("F?3","F13")=1
=SEARCH("F?3","F13")=1
在你的第二个例子中,如果 B3 包含通配符注入文本
In your second example, if B3 contains wildcards infused text
=SEARCH(B3,$DATA.$A$2:$A$1501)=1
=SEARCH(B3,$DATA.$A$2:$A$1501)=1
SEARCH 返回它找到第一个参数的位置.=1"确保字符串从第一个参数开始,而不是在中间的某个地方.我不确定你的 $DATA 参数是如何工作的,所以我只是逐字复制了它.
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.