views:

27

answers:

2

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

For example:

Col1    Col2
------------
1       5
3       4
4       6
7       6

The merged column should look like this:

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

Thanks!!

A: 

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

Margus
I've got 500 rows in each column and the merged columns turns out with 999 :S
Diego
Did `.Offset(1, 0)` fix your problem?
Margus
A: 

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.

Jazza