Combine 2 Ranges as One and copy to another worksheet
I have two different ranges that I want to combine as one, copy then paste to
another worksheet. My current code copies the Range("A3:T" & lngLastRow), why? I want to leave out the columns between Col.K and Col.T. Dim CopyPasteRanges() Dim lngLastRow As Long Dim rngSummary As Range Dim rngDept as Range lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row Set rngSummary = Sheets("Sheet1").Range("A3:K" & lngLastRow) Set rngDept = Sheets("Sheet1").Range("T3:T" & lngLastRow)) ' copy entire summary and dept column to dept Range(Union(rngSummary, rngDept)).Copy Destination:=Sheets("Sheet2").Range("A5") End Sub -- Cheers, Ryan |
Combine 2 Ranges as One and copy to another worksheet
Hello Ryan,
Ron de Bruin has some great stuff along the lines of what you are trying to do, see: Copy/Paste/Merge examples. http://www.rondebruin.nl/tips.htm HTH--Lonnie M. |
Combine 2 Ranges as One and copy to another worksheet
Hi Ryan
Remove the Range statement before "Union": Union(rngSummary, rngDept).Copy Destination:=Sheets("Sheet2").Range("A5") Regards, Per "RyanH" skrev i meddelelsen ... I have two different ranges that I want to combine as one, copy then paste to another worksheet. My current code copies the Range("A3:T" & lngLastRow), why? I want to leave out the columns between Col.K and Col.T. Dim CopyPasteRanges() Dim lngLastRow As Long Dim rngSummary As Range Dim rngDept as Range lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row Set rngSummary = Sheets("Sheet1").Range("A3:K" & lngLastRow) Set rngDept = Sheets("Sheet1").Range("T3:T" & lngLastRow)) ' copy entire summary and dept column to dept Range(Union(rngSummary, rngDept)).Copy Destination:=Sheets("Sheet2").Range("A5") End Sub -- Cheers, Ryan |
Combine 2 Ranges as One and copy to another worksheet
Thanks Per! Thats what I needed.
-- Cheers, Ryan "Per Jessen" wrote: Hi Ryan Remove the Range statement before "Union": Union(rngSummary, rngDept).Copy Destination:=Sheets("Sheet2").Range("A5") Regards, Per "RyanH" skrev i meddelelsen ... I have two different ranges that I want to combine as one, copy then paste to another worksheet. My current code copies the Range("A3:T" & lngLastRow), why? I want to leave out the columns between Col.K and Col.T. Dim CopyPasteRanges() Dim lngLastRow As Long Dim rngSummary As Range Dim rngDept as Range lngLastRow = Sheets("Sheet1").Cells(Rows.Count, "A").End(xlUp).Row Set rngSummary = Sheets("Sheet1").Range("A3:K" & lngLastRow) Set rngDept = Sheets("Sheet1").Range("T3:T" & lngLastRow)) ' copy entire summary and dept column to dept Range(Union(rngSummary, rngDept)).Copy Destination:=Sheets("Sheet2").Range("A5") End Sub -- Cheers, Ryan |
All times are GMT +1. The time now is 02:16 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com