且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如果值匹配,则将单元格数据连接到另一个数据中

更新时间:2023-02-04 20:20:54

您可能会为此使用用户定义函数(又名 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.