Home > Back-end >  More effective/elegant way of copying used ranges
More effective/elegant way of copying used ranges

Time:12-01

I'm trying to copy certain columns from a sheet to another (around 15).

My current method is less than ideal (I think).

Sheets(2).Range("A:A").Value = Sheets(1).Range("C:C").Value
Sheets(2).Range("C:C").Value = Sheets(1).Range("G:G").Value
Sheets(2).Range("D:D").Value = Sheets(1).Range("T:T").Value

It looks repetitive and more importantly it copies the entire column, which slows down the process by loading the empty rows until the end of the sheet as well.

I'm trying to figure out the best possible way to copy the columns just up to the last used column.

This is my current idea, but the empty cells in the second sheet are filled with the not available error value, which defeats the purpose.

lastRow = Sheets(1).Range("C" & Sheets(1).Rows.Count).End(xlUp).Row

Sheets(2).Range("A:A").Value = Sheets(1).Range("C1:C" & lastRow).Value

Any function that I'm probably not aware of? Thank you!

(And yes, this must be done in VBA. Ask my boss

  • Related