To combine text with the unique ID numbers, you can extract the unique values first and then create a User Defined Function to combine the names based on the unique ID.

1. Take the following data as example, you need to extract the unique ID numbers first, please apply this array formula: =IFERROR(INDEX($A$2:$A$15, MATCH(0,COUNTIF($D$1:D1, $A$2:$A$15), 0)),""),enter this formula into a blank cell, D2 for example, then press Ctrl + Shift + Enter keys together, see screenshot:

Tip: In the above formula, A2:A15 is the list data range you want to extract unique values from, D1 is the first cell of the column you want to put out the extracting result.

2. And then drag the fill handle down to extract all unique values until blanks displayed, see screenshot:

3. In this step, you should create a User Defined Function to combine the names based on the unique ID numbers, please hold down the ALT + F11 keys, and it opens the Microsoft Visual Basic for Applications window.

4. Click Insert > Module, and paste the following code in the Module Window.

VBA code: concatenate text based on criteria

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Function ConcatenateIf(CriteriaRange As Range, Condition As Variant, ConcatenateRange As Range, Optional Separator As String ","As Variant
'Update 20150414
Dim xResult As String
On Error Resume Next
If CriteriaRange.Count <> ConcatenateRange.Count Then
    ConcatenateIf = CVErr(xlErrRef)
    Exit Function
End If
For i = 1 To CriteriaRange.Count
    If CriteriaRange.Cells(i).Value = Condition Then
        xResult = xResult & Separator & ConcatenateRange.Cells(i).Value
    End If
Next i
If xResult <> "" Then
    xResult = VBA.Mid(xResult, VBA.Len(Separator) + 1)
End If
ConcatenateIf = xResult
Exit Function
End Function

5. Then save and close this code, go back to your worksheet, and enter this formula into cell E2, =CONCATENATEIF($A$2:$A$15, D2, $B$2:$B$15, ",") , see screenshot:

6. Then drag the fill handle down to the cells that you want to apply this formula, and all the corresponding names have been combined based on the ID numbers, see screenshot:

Tips:

1. In the above formula, A2:A15 is the original data which you want to combine based on, D2 is the unique value you have extracted, and B2:B15 is the name column that you want to combine together.

2. As you can see, I combined the values which are separated by comma, you can use any other characters by changing the comma “,” of the formula as you need.

Link: https://www.extendoffice.com/documents/excel/2723-excel-concatenate-based-on-criteria.html

最新文章

  1. istringstream的操作
  2. 第三个Sprint冲刺第九天
  3. ruby中数组的常用方法----例子
  4. Java中的数组排序
  5. 通过wifi调试Android程序
  6. mac 目录详解
  7. dede织梦怎么修改description的字数
  8. 什么是nrm
  9. c#十进制转二进制算法 和字符串反转算法
  10. 菜鸟脱壳之脱壳的基础知识(五)——利用内存断点寻找OEP
  11. vue element-ui 动态上传
  12. babel和postcss引起的一点儿思考
  13. org.joda.time.DateTime 日期格式
  14. 负载均衡下 tomcat session 共享
  15. AIX 批量更改密码
  16. python实现的摩斯电码解码\编码器
  17. 使用4K显示器遇到的坑
  18. Spark源码分析 &ndash; Deploy
  19. Swift学习——Swift基础具体解释(一)
  20. Qcon

热门文章

  1. python中enumerate的使用
  2. bzoj 2251: [2010Beijing Wc]外星联络 后缀数组
  3. 关于ADMM的研究(二)
  4. javascript 字符串转数字
  5. Jquery 获取表单值如input,select等方法
  6. 替换SQL Server字段中的换行符,回车符
  7. 【Android 复习】:第02期:引导界面(二)使用ViewPager实现欢迎引导页面
  8. (转载)AS3领航系列教程 之 AS3程序的入口
  9. Colour your Log4Net events in your RichTextBox zz
  10. windows下面配置jdk环境变量