Home » excel » EXCEL VBA: Append column from one worksheet to the end of another

EXCEL VBA: Append column from one worksheet to the end of another

Posted by: admin May 14, 2020 Leave a comment

Questions:

I currently have the below to copy the first column from sheet 2 to the first column in sheet 1

Sheets("Sheet2").Columns(1).Copy Destination:=Sheets("Sheet1").Columns(1)

However, this overwrites what is there – how would I append the data to what’s there already?

Thanks

How to&Answers:

Try,

dim arr as variant, i as long

arr = array("A", "B", "C", "G", "H", "I")

With Worksheets("Sheet2")
    for i=lbound(arr) to ubound(arr)
        .Range(.Cells(1, arr(i)), .Cells(.Rows.Count, arr(i)).End(xlUp)).Copy _
            Destination:=Worksheets("Sheet1").Cells(.Rows.Count, arr(i)).End(xlUp).Offset(1, 0)
    next i
End With

Answer:

Try copying the intersection of the UsedRange and Column(x), and pasting to the row below the used range:

With Sheets("Sheet2")
    Intersect(.UsedRange, .Columns(1)).Copy Sheets("Sheet1").Cells(Rows.Count,1).End(xlup).Offset(1,0)
End With