简体   繁体   English

Excel 公式检查相似名称并将它们的 id 添加到新列

[英]Excel formula to check similar names and add their ids to new column

I'm trying to do that third column in excel.我正在尝试在 excel 中做第三列。

I need a formula that could check the name column and find the ones with the same values then fetch their ids and put them together in the new column我需要一个公式,可以检查名称列并找到具有相同值的列,然后获取它们的 id 并将它们放在新列中

link to imgur, showing table data below链接到 imgur,下面显示表格数据

+--------+----+------------+
| Jack   |  1 | 1|2|3      |
| Jack   |  2 | 1|2|3      |
| Jack   |  3 | 1|2|3      |
| Emily  |  4 | 4|5        |
| Emily  |  5 | 4|5        |
| John   |  6 | 6|7|8      |
| John   |  7 | 6|7|8      |
| John   |  8 | 6|7|8      |
| Lauren |  9 | 9|10|11|12 |
| Lauren | 10 | 9|10|11|12 |
| Lauren | 11 | 9|10|11|12 |
| Lauren | 12 | 9|10|11|12 |
+--------+----+------------+

In case you won't able to access TEXTJOIN function, because of excel version issues You can make your own function for this.如果您因为 excel 版本问题而无法访问 TEXTJOIN function,您可以为此制作自己的 function。 Enjoy !!!享受 !!!

You can get a result like this my_solution你可以得到这样的结果my_solution

As you can see I have used function Lookup_delimited, Three arguments of Lookup_delimited are如您所见,我使用了 function Lookup_delimited,三个 arguments 的 Lookup_delimited 是

  1. Lookup value查找值

  2. Lookup_Range (Note: Don't choose the entire column, be specific with your lookup range) Lookup_Range(注意:不要选择整个列,具体说明您的查找范围)

  3. Results_Range (The values you want to consolidate) Results_Range(您要合并的值)

Steps to get this Lookup_delimited,获取此 Lookup_delimited 的步骤,

Step-1> Open your excel file步骤 1> 打开您的 excel 文件

Step-2> Press Alt+F11 (shortcut for VBA editor) Step-2> 按 Alt+F11(VBA 编辑器的快捷方式)

Step-3> Insert a new module Step-3> 插入新模块

Step-4> Paste the below code in there Step-4> 将下面的代码粘贴到那里

Step-5> Close your VBA editor, save your file as xlsm (Excel macro-enabled workbook) Step-5> 关闭 VBA 编辑器,将文件另存为 xlsm(启用 Excel 宏的工作簿)

Step-6> Your worksheet is ready to use the Lookup_delimited functions Step-6> 您的工作表已准备好使用 Lookup_delimited 函数

Step-7> Use this formula exactly as mentioned above Step-7> 完全按照上面提到的方式使用这个公式

Try This:尝试这个:

Option Explicit
Function Lookup_delimited(L_Value As Variant, L_Range As Range, R_Range As Range) As String


    Dim Stg As String 'Results storage
    Dim StgTmp As String  'Cell value storage
    Dim Rw As Long   'Row
    Dim Cl As Long   'Column

    Const StgDelimiter = " | "


    Stg = StgDelimiter
    For Rw = 1 To L_Range.Rows.Count
        For Cl = 1 To L_Range.Columns.Count
            If L_Range.Cells(Rw, Cl).Value = L_Value Then


                StgTmp = R_Range.Offset(Rw - 1, Cl - 1).Cells(1, 1).Value
                If InStr(1, Stg, StgDelimiter & StgTmp & StgDelimiter) = 0 Then
                    Stg = Stg & StgTmp & StgDelimiter
                End If
            End If
        Next
    Next


    Lookup_delimited = Stg 'Return to function


End Function

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

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