开发者

Excel merge columns

开发者 https://www.devze.com 2023-01-21 03:07 出处:网络
Hi all I want to merge to columns in excel 2003. For example: Col1Col2 ------------ 15 3开发者_Go百科4

Hi all I want to merge to columns in excel 2003.

For example:

Col1    Col2
------------
1       5
3  开发者_Go百科     4
4       6
7       6

The merged column should look like this:

Col3
----
1
3
4
4
5
6
6
7

Thanks!!


Assuming, that your Col1, Col2 and Col3 are Columns A, B and C, you can use makro:

Range("A1:" & Range("A65536").End(xlUp).Address).Select
Selection.Copy

Range("C1").Select
ActiveSheet.Paste

Range("B1:" & Range("B65536").End(xlUp).Address).Offset(1, 0).Select
Selection.Copy

Range("C65536").End(xlUp).Select
ActiveSheet.Paste

Source: link


Although you could easily use Excel's built-in functions to copy and paste the values from each column into the third column, you don't state if it's a requirement that the results in Col3 need to be sorted, or whether duplicate values should be removed or not. If so, you might have to write a user-defined function (equivalent to an Excel macro) in Excel VBA to do this.

Your solution might look like this (pseudo-code):

  • Iterate through all rows in Col1 and store values in an array
  • Iterate through all rows in Col2 and store values in a second array
  • Create a new array and combine the values from the other two arrays
  • Output the values from the combined array into Col3

Your function/macro will probably need to accept three input parameters which would be the ranges of the two source columns and the output column.

0

精彩评论

暂无评论...
验证码 换一张
取 消