如果值匹配,则将单元格数据连接到另一个数据中 [英] Concatenate cell data into another data if values matches
本文介绍了如果值匹配,则将单元格数据连接到另一个数据中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在同一个 Excel 表中有两个 列 A 和 B
.我正在尝试,如果 Column B
中的两个值匹配,那么它应该在同一行中复制相关值 A
.
I have two columns A and B
in same excel sheet. I am trying that if in Column B
two values matches then it should copy related value A
in same row.
例如
表格
Column A Column B
xyz 1
abc 1
pqr 1
eee 2
qqq 3
www 4
oop 5
期望输出
column A Column B
xyz,abc,pqr 1
eee 2
qqq 3
www 4
oop 5
推荐答案
您可能会为此使用用户定义函数(又名 UDF).将其放入模块表中.
You could probably use a User Defined Function (aka UDF) for this. Put this into a module sheet.
Public Function conditional_concat_strs(rSTRs As Range, rCRITs As Range, rCRIT As Range, Optional sDELIM As String = ", ")
Dim c As Long, sTMP As String
Set rSTRs = rSTRs.Cells(1, 1).Resize(rCRITs.Rows.Count, rCRITs.Columns.Count)
For c = 1 To rCRITs.Cells.Count
If rCRITs(c).Value2 = rCRIT Then _
sTMP = sTMP & rSTRs(c).Value & sDELIM
Next c
conditional_concat_strs = Left(sTMP, Application.Max(Len(sTMP) - Len(sDELIM), 0))
End Function
像任何本机工作表函数一样使用.
Use like any native worksheet function.
这篇关于如果值匹配,则将单元格数据连接到另一个数据中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文