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" ...
随机推荐
- raywenderlich-iOS设计模式Part 1/2【译】
原文地址:http://www.raywenderlich.com/86477/introducing-ios-design-patterns-in-swift-part-1 Update 04/22 ...
- C# RichTextBox 获取当前显示部分的文字
int start = richTextBox1.GetCharIndexFromPosition(new Point(0, 0)); int end = richTextBox1.GetCharIn ...
- HTML DOM select() 方法
定义和用法 select() 方法用于选择该元素中的文本. 语法 textareaObject.select() 实例 下面的例子可选择文本框中的文本: <html> <head&g ...
- 记录一次配置unix网络编程环境的过程和遇到的问题
记录一次搭建unix网络编程环境过程中遇到的问题和总结 计算机环境虚拟机 linuxmint-18-xfce-64bit 1.打开unix网络编程.iso 把目录下的文件复制到某一目录,修改权限,可命 ...
- OpenIOC
http://wenku.it168.com/d_926300.shtml OpenIOC http://safe.it168.com/a2015/1208/1790/000001790446.sht ...
- Buying Feed, 2010 Nov (单调队列优化DP)
约翰开车回家,又准备顺路买点饲料了(咦?为啥要说"又"字?)回家的路程一共有 E 公里,这一路上会经过 K 家商店,第 i 家店里有 Fi 吨饲料,售价为每吨 Ci 元.约翰打算买 ...
- 基于Maven的spring_security入门
配置文件的修改点没什么变化,可以参考:http://blog.csdn.net/ouitiken/article/details/8830505 pom.xml的依赖参考: <dependenc ...
- C++中new和不new的区别
我们都知道C++中有三种创建对象的方法,如下: 复制代码代码如下: #include <iostream>using namespace std; class A{private: ...
- 【HDOJ】2707 Steganography
简单字符串,读懂题,很容易AC. #include <stdio.h> #include <string.h> ], line[], des[]; int main() { i ...
- 求奇数偶数的和,,利用while循环
static void Main(string[] args) { while (true) { try ...