简体   繁体   English

如何在Excel中基于另一个列值连接一个列值?

[英]How to concatenate a column value based on another column value in excel?

I have sheet like this : 我有这样的表:

图片1

How can I concatenate values in column B based on value in column A . 如何基于column A值连接column B column A值。

Values corresponding to ID 1.1.1 are of B2:B5 Similarly, values for ID 1.1.2 are of B6:B8 and so on.. Its like it start from first id, lookup until next id, all values in column B until next Id in column A is concatenated 对应于ID 1.1.1值是B2:B5类似地,ID 1.1.2值是B6:B8 ,依此类推。就像它从第一个id开始,查找直到下一个id, column B所有值直到下一个。 column A ID已连接

the result should be like this : 2,3,4,5 in single cell of column D 结果应该是这样的: column D单个单元格中的2,3,4,5

I am not sure if this would solve your purpose, but you can keep concatenating values till the value in column A is same and use the last value. 我不确定这是否可以解决您的目的,但是您可以继续连接值,直到A列中的值相同并使用最后一个值。

Assuming the case you provided, paste the formula =IF(A2<>"",B2,D1&", "&B2) in cell D2 and copy throughout the column. 假设您提供了这种情况,请将公式=IF(A2<>"",B2,D1&", "&B2)粘贴到单元格D2并复制整个列。 You can additionally create a flag for changes in column E using =IF(A2<>"",1,"") in cell E2 . 您还可以使用单元格E2 =IF(A2<>"",1,"")为列E中的更改创建一个标志。 The results would be like this. 结果将是这样。

样本输出

It's still not quite clear, what you are trying to achieve, but to simply concatenate columns with a comma as separator, you can try something like the following: 您仍然想知道要实现的目标还不是很清楚,但是只需用逗号作为分隔符将列连接起来,您可以尝试执行以下操作:

In column d2 (or column d5), type in the following formula 在d2列(或d5列)中,键入以下公式

=B2&","&B3&","&B4&","&B5

That should get you in the right direction. 那应该给您正确的方向。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM