惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
博客园_首页
雷峰网
雷峰网
V
V2EX
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - Franky
月光博客
月光博客
Hugging Face - Blog
Hugging Face - Blog
WordPress大学
WordPress大学
T
Tailwind CSS Blog
小众软件
小众软件
博客园 - 叶小钗
美团技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
MyScale Blog
MyScale Blog
Blog — PlanetScale
Blog — PlanetScale
大猫的无限游戏
大猫的无限游戏
Jina AI
Jina AI
人人都是产品经理
人人都是产品经理
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 鸡毛信

改变你思维模式的书单 金字塔原理 BA的广度和深度 读书雷达 l 业务分析师(BA)篇 BA Practice Lead Handbook 1 - Why Is Business Analysis Taking The World By Storm? Making the Elephant Dance: Strategic Enterprise Analysis BABOK - 企业分析(Enterprise Analysis) BA - 读书雷达10本必读书 XMind十大最有用的功能 Excel中如何查找并列出所有链接(外部数据链接)? 在Excel里如何将多个工作簿合并到一个工作簿中 EXCEL 如何将多个工作表或工作簿合并到一个工作表 用Excel完成专业化数据统计、分析工作 需求 BA/PM Competency Module PPT 学习总结 PPT五大插件汇总下载 提高你30%的设计效率的PPT快捷键 PPT扁平化手册 2
How to easily concatenate text based on criteria in Excel...
鸡毛信 · 2016-08-08 · via 博客园 - 鸡毛信

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:

doc combine text based on criteria 2

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:

doc combine text based on criteria 3

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

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:

doc combine text based on criteria 4

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:

doc combine text based on criteria 5

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