如何在excel宏中匹配字符串通配符模式 [英] How to match a string wildcard pattern in an excel macro

查看:38
本文介绍了如何在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.

这篇关于如何在excel宏中匹配字符串通配符模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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