[英]Excel - formula link cells based on another column
I want to use a formula (or a function I'll make in VBA, I prefer a formula) to do the following: I have text in column A, that I want to link in Column E based on similar cells in column B. For example: cell B2,B3,B4 equals "A" and I want cell E2 to be the values in column A with a ";"我想使用一个公式(或我将在 VBA 中创建的函数,我更喜欢一个公式)来执行以下操作:我在 A 列中有文本,我想根据 B 列中的类似单元格在 E 列中链接。例如:单元格 B2、B3、B4 等于“A”,我希望单元格 E2 是 A 列中带有“;”的值between the values.值之间。
You can use an array formula for this: =TEXTJOIN(";",TRUE,IF(B:B=B2,A:A,""))您可以为此使用数组公式: =TEXTJOIN(";",TRUE,IF(B:B=B2,A:A,""))
Enter the formula in the bar in cell E2 and press ctrl + shift + enter to create an array formula.在单元格 E2 的栏中输入公式,然后按ctrl + shift + enter创建数组公式。
I am not sure how to do it using a formula but below VBA method will work.我不知道如何使用公式来做到这一点,但低于 VBA 的方法会起作用。
Use the method MultipleLookupNoRept in the formula在公式中使用 MultipleLookupNoRept 方法
Function MultipleLookupNoRept(Lookupvalue As String, LookupRange As Range, ColumnNumber As Integer) Dim i As Long Dim Result As String For i = 1 To LookupRange.Columns(1).Cells.Count If LookupRange.Cells(i, 1) = Lookupvalue Then For J = 1 To i - 1 If LookupRange.Cells(J, 1) = Lookupvalue Then If LookupRange.Cells(J, ColumnNumber) = LookupRange.Cells(i, ColumnNumber) Then GoTo Skip End If End If Next J Result = Result & " " & LookupRange.Cells(i, ColumnNumber) & ";"函数 MultipleLookupNoRept(Lookupvalue As String, LookupRange As Range, ColumnNumber As Integer) Dim i As Long Dim Result As String For i = 1 To LookupRange.Columns(1).Cells.Count If LookupRange.Cells(i, 1) = Lookupvalue Then For J = 1 To i - 1 If LookupRange.Cells(J, 1) = Lookupvalue Then If LookupRange.Cells(J, ColumnNumber) = LookupRange.Cells(i, ColumnNumber) Then GoTo Skip End If End If Next J 结果 = 结果& " " & LookupRange.Cells(i, ColumnNumber) & ";" Skip: End If Next i MultipleLookupNoRept = Left(Result, Len(Result) - 1) End Function跳过:End If Next i MultipleLookupNoRept = Left(Result, Len(Result) - 1) End 函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.