Excel公式查找单元格中的第一个非字母字符?
有没有办法使用 Excel 中的单元格公式来查找引用单元格中第一个非字母字符的索引?
我已将数据导入到 Excel 中,其中有一列如下所示:
<派生单元格中我不想要的某些文本><在我想要的文本前面添加并且始终为常量的某些文本>TheTextIWant<一些非字母字符><一些可能是字母或不是字母的其他字符>
我正在尝试创建一个到目前为止看起来像这样的公式:
=MID(<单元格引用>, SEARCH ("<前置文本>, <单元格引用>) + <前置文本的长度>, ??)
其中 ?? 是一些子公式,用于查找“TheTextIWant”之后的第一个非字母字符
这可能吗?
Is there a way using a cell formula in Excel to find the index of the first non-alpha character in a referenced cell?
I've imported data into Excel which has a column that looks like this:
<some text I don't want in the derived cell><some text that prepends the text I want and is always constant>TheTextIWant<Some non-alpha character><some other characters that may be alpha or not>
I'm trying to create a formula that so far looks like this:
=MID(<cell reference>, SEARCH("<prepended text>, <cell reference>) + <length of prepended text>, ??)
Where ?? is some sub-formula that finds the first non-alpha character after "TheTextIWant"
Is this possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面的公式从字符串中提取数字,类似的方法也可用于提取非字母字符,只需将所需的字符而不是数字放在括号中即可
The following formula extracts numbers from the string , similar way can be used to extract non alpha characters , just place the characters required instead of the numbers in the bracket
要更详细地了解数组公式的工作原理(@Jacob 的公式在某些情况下似乎略有错误,例如 0 代表“A1A”),所以这是我认为是一个工作版本,为了便于使用而进行了扩展阅读。请让我知道任何它不起作用的例子。
这是传递给 IF 的条件数组。然后通过重复步骤 1 构建第二个数组,其中包含每个字符的位置。 IF 函数在数组模式下生成输出数组。条件为 TRUE 的情况被设置为字符位置数组中的相应值,其余的全部设置为 LEN(A1)+1,因此它们大于任何数字字符的任何可能位置值。
然后,MIN 函数计算 IF 输出的数组,返回最小值,即单元格 A1 中字符串中第一个数字字符的位置。如果单元格中没有文本,最外面的 IF 函数会强制公式返回 0,而不是 1;否则,间接返回#REF!搜索单元格 A0 时出错,向上传播,IF 返回 FALSE 条件,返回 0 + 1 = 1。
要搜索第一个非数字字符的位置,只需颠倒顺序即可IF 的后 2 个参数:
To go into a bit more detail about how the array formula works (@Jacob's formula seems to be slightly wrong in a couple of cases, e.g. 0 for "A1A"), so here's what I think is a working version, expanded for ease of reading. Please let me know of any examples where it doesn't work.
This is the array of conditions passed to IF. A second array is then constructed by repeating step 1, containing the position of each character. The IF function, in array mode, produces an array of outputs. Cases whose condition is TRUE are set to the corresponding value from the array of character positions, and the rest are all set to LEN(A1)+1 so they are larger than any possible position values for any numeric characters.
The MIN function then evaluates the array output by IF, returning the smallest value, which is the position of the first numeric character in the string in cell A1. The outermost IF function forces the formula to return 0 if there is no text in the cell, rather than 1; otherwise, INDIRECT returns a #REF! error when searching for cell A0, which propagates upwards, and the FALSE condition is returned by IF, returning 0 + 1 = 1.
To search for the position of the first non-numeric character instead, all you have to do is reverse the order of the second 2 arguments to IF:
在此页面有一个数组公式,用于查找“A 中第一个数字的位置”细绳。”您应该能够修改它以使用“T”函数(以确定字符是否是文本),结合一点减法,然后得到您正在寻找的内容。
On this page there is an array formula for finding the "Position Of First Digit In A String." You should be able to modify that to use the 'T' function (to determine if a character is text), incorporate a little subtraction and then get to what you're looking for.