0
4

2 回答 2

0

这可能是使用 VBA 中的用户定义函数完成的一个很好的解决方案:

Public Function someTest(firstVal As String, ParamArray otherVal() As Variant) As String

    Dim someVal As Variant
    Dim delim As String:    delim = "|"
    Dim splitVal As String: splitVal = "-"

    For Each someVal In otherVal
        someTest = someTest & Split(firstVal, splitVal)(0) & delim & someVal
    Next someVal

End Function

这就是你所说的:

在此处输入图像描述

该函数使用ParamArray()并遍历它的每个元素,并与第一个参数的第一部分连接。因此,English-testEnglish取自。


稍作改动,就可以将第二个参数作为范围传递。因此,它会更容易一些:

Public Function someTest2(firstVal As String, otherVal As Range) As String

    Dim someVal As Range
    Dim delim As String:    delim = "|"
    Dim splitVal As String: splitVal = "-"

    For Each someVal In otherVal
        someTest2 = someTest2 & Split(firstVal, splitVal)(0) & delim & someVal
    Next someVal

End Function

在此处输入图像描述

这里的第二个参数是一个范围。每个范围至少有一个单元格,因此函数循环遍历单元格。

于 2018-05-23T08:50:20.457 回答
0

用公式解决;不如 UDF 可扩展性:

=SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(Rest,"test",Extras1&"|",1),"test",Extras2&"|",1),"test",Extras3&"|",1),"|" ,"",COUNTA(Extras1:Extras3))

于 2018-05-23T09:33:17.263 回答