简体   繁体   English

Excel 公式查找索引的匹配部分

[英]Excel formula to find matching part of index

I'm working with structure like tree graph.我正在使用像树图这样的结构。 I have items where each one has index telling where it appears in the tree.我有项目,每个项目都有索引,告诉它出现在树中的位置。 Then i get groups of items like this:然后我得到这样的项目组:
Item 1: A-1-1-2-1-1-1第 1 项:A-1-1-2-1-1-1
Item 2: A-1-1-1-1-2项目 2:A-1-1-1-1-2
Item 3: A-1-1-2-1-1-2第 3 项:A-1-1-2-1-1-2
Item 4: A-1-1-2-1第 4 项:A-1-1-2-1

What i need to find is common part of index for each group.In this example a common part would be "A-1-1-".我需要找到的是每个组的索引的公共部分。在这个例子中,一个公共部分是“A-1-1-”。
Is it possible to find matching part of the string in another string using excel formulas?是否可以使用 excel 公式在另一个字符串中找到匹配的部分字符串? My collague said i'd need to make vba macro using recursion to find only part of matching string, but maybe there's simplier solution we didn't find.我的同事说我需要使用递归制作 vba 宏以仅查找匹配字符串的一部分,但也许我们没有找到更简单的解决方案。

Use:利用:

=LEFT(A1,MAX(IF(COUNTIF(A1:A4,LEFT(A1,ROW($ZZ$1:INDEX($ZZ:$ZZ,LEN(A1))))&"*")=COUNTA(A1:A4),ROW($ZZ$1:INDEX($ZZ:$ZZ,LEN(A1))))))

Depending on one's version this may need to be confirmed with Ctrl-Shift-Enter instead of Enter when exiting edit mode.根据一个人的版本,这可能需要在退出编辑模式时使用 Ctrl-Shift-Enter 而不是 Enter 来确认。

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM