简体   繁体   中英

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. 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.

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.

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也可以

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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