简体   繁体   English

将单个单元格中的B列行值与A列连接

[英]Concatenate column B row values in single cell against column A

I have data around 400+ records in column "A" & various detail in column "B". 我在“ A”列中有大约400多个记录的数据,在“ B”列中有各种详细信息。 A total of 3000+ rows in the sheet which look like Example: 工作表中共有3000多个行,例如:

Column A    Column B

CHI150  UPS1

CHI150  TOWER1

CHI150  TOWER2

CHI160  EB1

CHI160  UPS1

CHI160  TOWER1

CHI163  EB1

CHI163  TOWER2

CHI163  UPS2

CHI195  TOWER1

CHI195  EB1

I want do concatenate the data like below mentioned. 我想像下面提到的那样连接数据。

Column A    Column B

CHI150  UPS1, TOWER1, TOWER2

CHI160  EB1, UPS1, TOWER1

CHI163  EB1, TOWER2, UPS2

CHI195  TOWER1, EB1

Kindly give the solution & Thanks in advance 请给解决方案,并在此先感谢

Assuming you have the data in Column A & B from A2 and B2 cells respectively.. 假设您在A和B列中分别有来自A2和B2单元的数据。

 Sub test() 'change the sheet name as yours Sheets("Sheet1").Activate 'Change the range as yours and you need update the column as well in cells(rows.count,1) Set Rng = Range("A2", Cells(Rows.Count, 1).End(xlUp)) Set rng1 = Range("D2", Cells(Rows.Count, 4).End(xlUp)) Range("A2", Cells(Rows.Count, 1).End(xlUp)).Copy 'copy pasteing the column A and removing duplicates Range("D2").PasteSpecial xlPasteValues ActiveCell.RemoveDuplicates Columns:=1, Header:=xlNo ' now concordinating the values For Each cell In rng1 For Each cell1 In Rng If cell.Value = cell1.Value Then If cell.Offset(0, 1).Value = "" Then cell.Offset(0, 1).Value = cell1.Offset(0, 1).Value Else cell.Offset(0, 1).Value = cell.Offset(0, 1).Value & ", " & cell1.Offset(0, 1).Value End If End If Next cell1 Next cell End Sub 

在此处输入图片说明

The above macro will generated the result in column D form D2. 上面的宏将在D列的D2表格中生成结果。 Hope this is what your expecting.. 希望这是您的期望。

Thanks for making the changes in your question to explain it better. 感谢您对问题进行更改以更好地说明问题。

I took a sample sheet similar to your problem, and was able to get the desired result in a new column C. Try below steps 我制作了一个与您的问题类似的样本表,并能够在新的列C中获得所需的结果。请尝试以下步骤

  1. Copy the value of B1 to C1 将B1的值复制到C1
  2. Put below formula to all rows of column C starting from row 2 (ie C2). 在公式下方,从第2行(即C2)开始到C列的所有行。 This will check if value on column A at current row is similar to the previous row, and shall append the values of the column B to the calculated value in Column C for previous row. 这将检查当前行的A列上的值是否与上一行相似,并将B列的值附加到C列中针对上一行的计算值。

    =IF(A2=A1, (C1 & ", " & B2), B2) = IF(A2 = A1,(C1&“,”&B2),B2)

  3. For all the rows of column D, put below formula starting with row 1 对于D列的所有行,将公式放在第1行开始的下方

    =IF(A1=A2,"","Changed") = IF(A1 = A2, “”, “改变”)

  4. This should fill some of the rows for column D with "Changed", you could then filter for the column D for only the records that contain "Changed" as value. 这应该用“ Changed”填充D列的某些行,然后可以仅针对包含“ Changed”作为值的记录过滤D列。

This should get you desired result. 这应该得到您想要的结果。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果A列中的单元格为空,则针对不同工作表中的数据集进行vlookup列B - if cell in column A is blank then vlookup column B against dataset in different sheet 如何通过A列中的奇异值连接B列中的唯一值 - How to concatenate unique values in column B by singular values in column A 将 A 列数据的行连接到第一行 B 列的单个单元格时遇到问题 - Facing issues when joining rows of A column data into single cell at B column of 1st row 动态逐行连接列值 - Concatenate Column Values Row by Row Dynamically 如何使用Excel VBA将A列的值连接到B列 - How to concatenate the Column A values to Column B Using Excel VBA 如果 A 列中的单元格等于 B 列中的单元格,则 Excel 宏将删除一行 - Excel Macro to delete a row if cell in Column A equals cell in Column B 如果列A单元格与列B单元格匹配,则显示与列B相同的行的C列值 - if Column A cell matches Column B cell, display column C value of same row as column B 连接交替的固定列标题和行值 - Concatenate alternating fixed column headers and row values VBA-在B列中找到A列上的商品的所有值,并将它们放在一行中 - VBA - Find all values on column B for article on column A and place them to a single row 如何串联来自不同行的单行列中的列 - How to concatenate column in single row column from different rows
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM