[英]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中获得所需的结果。请尝试以下步骤
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)
For all the rows of column D, put below formula starting with row 1 对于D列的所有行,将公式放在第1行开始的下方
=IF(A1=A2,"","Changed") = IF(A1 = A2, “”, “改变”)
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.