Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default 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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default 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.
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,533
Default 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


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default 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



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
trying to copy a worksheet containing named ranges to anotherworksheet cil9mxm Excel Worksheet Functions 1 December 3rd 08 06:06 PM
Combine multiple ranges into one worksheet Troy Man Excel Discussion (Misc queries) 1 September 30th 08 05:57 AM
Copy Worksheet with Named Ranges KC Rippstein hotmail com> Excel Programming 2 June 7th 08 06:04 AM
Copy worksheet ranges from One Workbook to another from halem2 Excel Worksheet Functions 0 March 24th 06 01:42 PM
Copy Worksheet plus ranges Ray Batig Excel Programming 2 March 16th 05 10:56 PM


All times are GMT +1. The time now is 04:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"