简体   繁体   English

Excel - 基于另一列的公式链接单元格

[英]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 的方法会起作用。

  1. Press Alt + F11 in the worksheet to open the VBA editor window在工作表中按 Alt + F11 打开 VBA 编辑器窗口
  2. In the left pane, Right click sheet1 and Insert module在左窗格中,右键单击 sheet1 并插入模块
  3. Copy paste the below method复制粘贴以下方法
  4. 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.

相关问题 根据另一个单元格信息自动填充 excel 中的单元格的公式 - Formula to auto populate cells in excel based on another cells information EXCEL-是否有公式将包含特定文本的所有单元格复制到另一列? - EXCEL - is there a formula to copy all the cells containing specific text to another column? Excel 公式根据另一列中的值填充一列 - Excel formula to fill a column based on value in another column Excel公式根据另一列值复制一列 - Excel formula to copy a column based on another column value Excel 公式 - 基于另一列结果的列更改 - Excel formula - column changes based on result of another column Excel SQL 根据另一列的范围在列中向下粘贴公式 - Excel SQL Paste Formula down in column based on range of another column 根据其他列从excel中的列中选择特定的单元格 - Selecting specific cells from a column in excel based on another column 根据 Excel 2010 中另一列的日期平均一列中的单元格 - Averaging cells in one column based on date of another column in Excel 2010 Excel VBA - 根据另一列中的值填充一列中的单元格 - Excel VBA - populate cells in one column based on values in another one Excel公式可将特定单元格从一行链接到另一行,并计算平均值/标准dev /模式 - Excel formula to link specific cells from one row to another and calculate mean/standard dev/mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM