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

How to easily concatenate text based on criteria in Excel? 如何将Excel中的文本按条件合并的更多相关文章

  1. Android TextView : “Do not concatenate text displayed with setText”

    参考:http://stackoverflow.com/questions/33164886/android-textview-do-not-concatenate-text-displayed-wi ...

  2. AsciiDoc Text based document generation

    AsciiDoc Text based document generation    AsciiDoc Home Page http://asciidoc.org/   AsciiDoc is a t ...

  3. OpenCV_contrib里的Text(自然场景图像中的文本检测与识别)

    平台:win10 x64 +VS 2015专业版 +opencv-3.x.+CMake 待解决!!!Issue说明:最近做一些字符识别的事情,想试一下opencv_contrib里的Text(自然场景 ...

  4. 关于iOS中的文本操作-管理text fields 和 text views

    Managing Text Fields and Text Views 管理UITextField和UITextView实例 UITextField和UITextView的实例拥有两个最主要的功能:展 ...

  5. 【JAVAEE学习笔记】hibernate04:查询种类、HQL、Criteria、查询优化和练习为客户列表增加查询条件

    一.查询种类 1.oid查询-get 2.对象属性导航查询 3.HQL 4.Criteria 5.原生SQL 二.查询-HQL语法 //学习HQL语法 public class Demo { //基本 ...

  6. 关于在JTextPane(或JEditorPane)中返回文本部分(Text)

    今天遇到这样的一个问题,我需要取得当前JTextPane()中的文件,但是 JTextPane.getText()返回的是网页的HTML源代码,在网上搜索了一下,找到了一个方法: //返回消息框的无格 ...

  7. html中去掉文本框(input type="text")的边框或只显示下边框

    去掉: <input   type="text"   name="textfield"   style="border:0px;"&g ...

  8. JAVAEE学习——hibernate04:查询种类、HQL、Criteria、查询优化和练习为客户列表增加查询条件

    一.查询种类 1.oid查询-get 2.对象属性导航查询 3.HQL 4.Criteria 5.原生SQL 二.查询-HQL语法 //学习HQL语法 public class Demo { //基本 ...

  9. 如何获取select中的value、text、index相关值 && 如何获取单选框中radio值 && 触发事件 && radio 默认选中

    如何获取select中的value.text.index相关值 select还是比较常用的一个标签,如何获取其中的内容呢? 如下所示: <select id="select" ...

随机推荐

  1. .Net平台下的B/S开发框架

    一.前言 本文主要是对.Net平台下的几种B/S开发框架进行比较.只对比前端展现和界面业务逻辑的部分,对于后台的数据层.业务层.持久层等则不作讨论,因为这些部分是完全可以共用的.  主要从如下几个维度 ...

  2. KMP模板与讲解

    读书笔记终于写完了,写一下我对KMP的理解. KMP的思想就是尽量利用已经得到的信息,来降低时间复杂度,已经得到的信息存放在next数组里.算法确实很难理解,所以很难讲解..举个例子来说吧. 设字符串 ...

  3. Memcached(一)在Windows上安装和测试memcached

    1)下载memcached的windows安装程序 memcached-1.2.4-Win32-Preview-20080309_bin.zip 或其他版本 2)解压memcached  用管理员身份 ...

  4. Ubuntu 安装 JDK 7 / JDK8 的两种方式

    ubuntu 安装jdk 的两种方式: 1:通过ppa(源) 方式安装. 2:通过官网下载安装包安装. 这里推荐第1种,因为可以通过 apt-get upgrade 方式方便获得jdk的升级 使用pp ...

  5. Android使用pull解析xml

    一.理论准备     Pull解析器的运行方式与 SAX 解析器相似.它提供了类似的事件,如:开始元素和结束元素事件,使用parser.next()可以进入下一个元素并触发相应事件.跟SAX不同的是, ...

  6. .h头文件、 .lib库文件、 .dll动态链接库文件之间的关系

    转自.h头文件. .lib库文件. .dll动态链接库文件之间的关系 h头文件作用:声明函数接口 dll动态链接库作用:含有函数的可执行代码 lib库有两种: (1)静态链接库(Static Liba ...

  7. forward:hello 与 redirect:hello的区别

    对于某些Controller的处理方法,当返回值为String类型时,返回的结果中可能含有forward或redirect前缀: 如: @Controller @RequestMapping(&quo ...

  8. String, StringBuffer, StringBuilder比较

    1.见API: String是不可变的字符序列: StringBuffer是线程安全的,可变的字符序列: StringBuilder是可变的字符序列: StringBuffer与String的区别是S ...

  9. Delphi XML-RPC 中文乱码解决方法

    http://download.csdn.net/user/csm2432/uploads/2

  10. Centos6.5 安装Vim7.4

    系统本身会带Vim7.2都版本,其实也够用,强迫症患者可以按以下操作升级成Vim7.4: (1)切换到root权限 (2)卸载 rpm -qa | grep vim yum remove vim vi ...