简体   繁体   English

在Excel中合并列

[英]Merging Columns in Excel

I have an excel sheet with two columns A and B. I need to merge these columns and have the result be separated by commas. 我有一个带有两列A和B的Excel工作表。我需要合并这些列,并用逗号分隔结果。 For example: 例如:

Column A | Column B
1 2

Would become 会成为

Column C

1,2

If possible I would like this to be done with VBA or an excel formula executed by VBA. 如果可能,我希望使用VBA或VBA执行的excel公式来完成此操作。

This will take an initial range (defined as rng) cycle through all the rows in this range outputting the contents of column A and B in that row to column C in the same row. 在此范围内的所有行中,这将花费一个初始范围(定义为rng),并将该行中A列和B列的内容输出到同一行中的C列。

set rng = Range(cells(1,1), cells(activesheet.UsedRange.Rows,1))
for each cell in rng
    cell.offset(0,2) = cell & "," & cell.offset(0,1)
next cell

这是一个excel公式

=CONCATENATE(A1,",", B1)

= A1&“,”&B1也可以

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

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