How to easily concatenate text based on criteria in Excel? 如何将Excel中的文本按条件合并
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 20150414Dim xResult As StringOn Error Resume NextIf CriteriaRange.Count <> ConcatenateRange.Count Then ConcatenateIf = CVErr(xlErrRef) Exit FunctionEnd IfFor i = 1 To CriteriaRange.Count If CriteriaRange.Cells(i).Value = Condition Then xResult = xResult & Separator & ConcatenateRange.Cells(i).Value End IfNext iIf xResult <> "" Then xResult = VBA.Mid(xResult, VBA.Len(Separator) + 1)End IfConcatenateIf = xResultExit FunctionEnd 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
How to easily concatenate text based on criteria in Excel? 如何将Excel中的文本按条件合并的更多相关文章
- Android TextView : “Do not concatenate text displayed with setText”
参考:http://stackoverflow.com/questions/33164886/android-textview-do-not-concatenate-text-displayed-wi ...
- AsciiDoc Text based document generation
AsciiDoc Text based document generation AsciiDoc Home Page http://asciidoc.org/ AsciiDoc is a t ...
- OpenCV_contrib里的Text(自然场景图像中的文本检测与识别)
平台:win10 x64 +VS 2015专业版 +opencv-3.x.+CMake 待解决!!!Issue说明:最近做一些字符识别的事情,想试一下opencv_contrib里的Text(自然场景 ...
- 关于iOS中的文本操作-管理text fields 和 text views
Managing Text Fields and Text Views 管理UITextField和UITextView实例 UITextField和UITextView的实例拥有两个最主要的功能:展 ...
- 【JAVAEE学习笔记】hibernate04:查询种类、HQL、Criteria、查询优化和练习为客户列表增加查询条件
一.查询种类 1.oid查询-get 2.对象属性导航查询 3.HQL 4.Criteria 5.原生SQL 二.查询-HQL语法 //学习HQL语法 public class Demo { //基本 ...
- 关于在JTextPane(或JEditorPane)中返回文本部分(Text)
今天遇到这样的一个问题,我需要取得当前JTextPane()中的文件,但是 JTextPane.getText()返回的是网页的HTML源代码,在网上搜索了一下,找到了一个方法: //返回消息框的无格 ...
- html中去掉文本框(input type="text")的边框或只显示下边框
去掉: <input type="text" name="textfield" style="border:0px;"&g ...
- JAVAEE学习——hibernate04:查询种类、HQL、Criteria、查询优化和练习为客户列表增加查询条件
一.查询种类 1.oid查询-get 2.对象属性导航查询 3.HQL 4.Criteria 5.原生SQL 二.查询-HQL语法 //学习HQL语法 public class Demo { //基本 ...
- 如何获取select中的value、text、index相关值 && 如何获取单选框中radio值 && 触发事件 && radio 默认选中
如何获取select中的value.text.index相关值 select还是比较常用的一个标签,如何获取其中的内容呢? 如下所示: <select id="select" ...
随机推荐
- 2016030207 - sql50题练习(脚本)
我的mysql版本是5.下面是要进行sql练习题使用的脚本.脚本是我整理出来的,在我本地直接复制执行就可以使用! 参考网址是:http://blog.csdn.net/zhangyulin54321/ ...
- 和阿木聊Node.js
npm:node.js官方库 cnpm:taobao维护的库: WebStorm:Node.js的开发工具,但是收费: seajs:还有一款交requirjs,前者是遵循amd规范(一次性参数中加载要 ...
- githubRepository -- 使用
1. 注册github账号; 2. 配置SSH keys; 点击setting, 配置 SSH keys Generating SSH keys 检查本地的 SSH keys: a> 在用户目录 ...
- 打开网页自动弹出qq客户端
新建js后调用即可,打开网站自动弹出qq对话框,若qq为关闭状态则启动qq,之后弹出对话框. document.write("<iframe src='tencent://messag ...
- Mybatis 学习
1. Mybatis 中 # 与 $ 符号的区别: a. #将传入的数据都当成一个字符串,会对自动传入的数据加一个双引号. 如:order by #user_id#,如果传入的值是12,那么解 ...
- 在windows下创建.gitignore文件
1.使用另存为的方式 2.在win7下,文件名输入 ”.gitignore.“ http://hbiao68.iteye.com/blog/2055496 http://lyhopq.github ...
- [wikioi]线段覆盖 2
http://wikioi.com/problem/3027/ # 有个小错误调了半天,最终发现sort(line, line+N)错了,后面那个是exclusive的,所以要line+N+1.# 按 ...
- [mock]10月11日
第二次mock.出的题是,假设有一个地区不能使用7,都用之后的数字代替,比如8代表7,18代表16(中间有7和17).那么给出一个这个地区的数X,求普通地区的数Y.首先是找规律,发现其实就是找给出的数 ...
- 简析LIVE555中的延时队列
http://www.cnblogs.com/nightwatcher/archive/2011/04/10/2011158.html 最近在看LIVE555的源码,感觉其中的延时队列写的不错,于是就 ...
- Qt无边框MainWindow如何拖动四周改变大小
原来还有winEvent(), x11Event() and macEvent() 这些东西...不过貌似还需要找更好的办法,否则就无法跨平台了. 你需要重新处理部分窗体事件,以下代码适用于Windo ...