UDF to concatenate values

前端 未结 2 826
深忆病人
深忆病人 2021-01-15 13:09

I am trying to build a user defined function using VBA for excel. That would concatenate a list of stores which has a x mark in that row.

   Store1 Store2 St         


        
2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-15 13:51

    Short but intricate.

    1. uses Evaluate to return an array of matches (Store numbers v x)
    2. Filter removes the non-matches ("V")
    3. Join to make the string from the final array of matches

    UDF

    Function Getx(Rng1 As Range, Rng2 As Range) As String
    Getx = Join(Filter(Evaluate("=ÏF(" & Rng2.Address & "=""x""," & Rng1.Address & ",""V"")"), "V", False), ",")
    End Function
    

提交回复
热议问题