Excel 文本公式提取字段中以分号分隔的单词
Excel 中的字段包含用分号分隔的单词,例如:
A1 = 保存;国家;宝藏;为;善
如何应用 Excel 文本公式在另一个字段中从该字段生成单独的单词?例如:
A2 should contain a formula to get the first word ("save")
A3 should contain a (different) formula to get the second word ("the")
etc.
然而,即使 A1 中的值发生变化,这些公式也应该保持有效,例如,如果 A1 的值更改为
A1 = 你好;那里;怎么样;是;你
在这方面的任何帮助将不胜感激。
(问题是在这种情况下不允许编写我自己的函数,我必须使用原始函数,例如 find
、search
、mid
, ETC。)
A field in Excel contains words separated by semicolons, e.g.:
A1 = save;the;national;treasure;for;good
How can I apply Excel text formulas to produce separate words from this field in another fields? E.g.:
A2 should contain a formula to get the first word ("save")
A3 should contain a (different) formula to get the second word ("the")
etc.
However these formulas should hold good even when the value in A1 changes, e.g. if the value of A1 is changed to
A1 = hello;there;how;are;you
Any help in this respect will be highly appreciated.
(The problem is writing a function of my own is not allowed in this case, I have to use original functions like find
, search
, mid
, etc.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以创建一个 VBA 函数来拆分此示例中的字段:
然后是 A2 公式将是:
=ExtractElement(A1, 1, ";")
和 A3 将是:=ExtractElement(A1, 2, ";")
等等You can create a VBA function to split the fields from this example:
Then the A2 formula would be:
=ExtractElement(A1, 1, ";")
and A3 would be:=ExtractElement(A1, 2, ";")
and so on如果您要在 A1 中解析文本,则以下公式应该有效
在 A2 中输入公式
在 B2 中输入公式
您可以根据需要将它们复制下来。 A 列抓取最左边的单词,B 列显示要解析的剩余字符串。如果没有足够的单词来解析,则公式将显示空白。 B 列也可以隐藏。
If you have your text to parse in A1 then the following formulas should work
In A2 enter the formula
In B2 enter the formula
You can then copy those down as far as you need. Column A grabs the left most word, and Column B displays the remaining string to be parsed. If it runs out of words to parse the formula will display a blank. Column B can also be hidden.
如果您可以使用中间公式,那么这将起作用:
A1 -- save;the;national;treasure;for;good
B1 -- Blank
C1 -- =IFERROR(FIND(";",$A1,1+(B1) ),LEN($A1)+1)
将 C1 复制到 D1:H1
C2 -- =MID($A1,B1+1,(C1-B1)-1)
将 C2 复制到 D2:H2
第 1 行将显示A1 中的每个分号,因为它开始在字符串中查找前一个单元格中找到的分号后面的一个字符。
例如,单元格 E1 从 D1+1 =10 开始在 A1 中搜索分号。
C1:H1 中的 iferror 语句捕获当搜索找不到进一步的分号时将发生的错误,并返回字符串 A1 的完整长度,并在结尾处加 1 为虚构的分号。
B1 需要留空才能创建初始零。
然后,单元格 C2:H2 使用 Mid 函数复制 A1 字符串的部分,该部分从每个 B1:G1 中的值之后的一个字符开始,长度为 (C1-B1)-1、(d1-c1)-1 等(减去一个删除分号本身)
您应该在第 1 行中得到:5, 9,18,27,31,36,并在这些单元格下方显示各个单词。
希望这有帮助。
If you can use intermediate formulae, then this will work:
A1 -- save;the;national;treasure;for;good
B1 -- blank
C1 -- =IFERROR(FIND(";",$A1,1+(B1)),LEN($A1)+1)
copy C1 into D1:H1
C2 -- =MID($A1,B1+1,(C1-B1)-1)
copy C2 into D2:H2
Row 1 will display the position of each semi-colon in A1, because it starts looking in the string one character past the semi-colon found in the previous cell.
eg cell E1 searches for a semi-colon in A1 starting at D1+1 =10.
The iferror statement in C1:H1 traps the error which will occur when the search finds no further semi-colons, and returns the full length of string A1, plus 1 for an imaginary semi-colon at the end.
B1 needs to be blank to create an initial zero.
Cells C2:H2 then use the Mid function to copy the section of the A1 string starting one character after the value in each of B1:G1, with length (C1-B1)-1, (d1-c1)-1 etc (minus one to cut out the semi-colon itself)
You should get: 5, 9,18,27,31,36 in Row 1, and beneath those cells the individual words.
Hope this helps.