PDA

View Full Version : [SOLVED] VBA Merge two tables into one



kikim
08-26-2014, 10:48 PM
Hello:hi:! There is a table (A1) on the sheet "1" and the table(A1) on the sheet "2", how to merge them on the sheet "3"? Tables only with one column.
: pray2:

mancubus
08-27-2014, 12:27 AM
welcome to the forum.

an easy to understand approach to copy one column could be:


Sub merge_wss()

Worksheets("Sheet3").Cells.Clear 'clear previous data
Worksheets("Sheet1").Range("A1").Copy Worksheets("Sheet3").Range("A1") 'copy header

Worksheets("Sheet1").Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).Copy _
Worksheets("Sheet3").Cells(Rows.Count, "A").End(xlUp).Offset(1)

Worksheets("Sheet2").Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row).Copy _
Worksheets("Sheet3").Cells(Rows.Count, "A").End(xlUp).Offset(1)

End Sub


for multiple columns, for ex 6 columns A:F, you can use "A2:F" instead of "A2:A".

kikim
08-27-2014, 01:51 AM
I tried and received it:
==============
Sheet1
==============
Name
1
2
3
4
==============
Sheet2
==============
Name
5
6
7
8
==============
Sheet3
==============
Name
Name
1
2
3
4
Name
5
6
7
8
___________________
Shall be
==============
Sheet3
==============
Name
1
2
3
4
5
6
7
8

mancubus
08-27-2014, 02:11 AM
same data, same code.
download and test attachment.

kikim
08-27-2014, 02:50 AM
Hmm, really everything works. Probably, something went wrong. Thank you.