PC Review


Reply
Thread Tools Rate Thread

Combine 2 Ranges as One and copy to another worksheet

 
 
RyanH
Guest
Posts: n/a
 
      16th Sep 2008
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 With Quote
 
 
 
 
Lonnie M.
Guest
Posts: n/a
 
      16th Sep 2008
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.
 
Reply With Quote
 
Per Jessen
Guest
Posts: n/a
 
      16th Sep 2008
Hi Ryan

Remove the Range statement before "Union":

Union(rngSummary, rngDept).Copy Destination:=Sheets("Sheet2").Range("A5")

Regards,
Per


"RyanH" <(E-Mail Removed)> skrev i meddelelsen
news:623A38A6-B2E7-4FB4-A08D-(E-Mail Removed)...
>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 With Quote
 
RyanH
Guest
Posts: n/a
 
      16th Sep 2008
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" <(E-Mail Removed)> skrev i meddelelsen
> news:623A38A6-B2E7-4FB4-A08D-(E-Mail Removed)...
> >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 With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Combine multiple ranges into one worksheet Troy Man Microsoft Excel Misc 1 30th Sep 2008 05:57 AM
Copy Worksheet with Named Ranges KC Rippstein hotmail com> Microsoft Excel Programming 2 7th Jun 2008 06:04 AM
Attempting to copy multiple ranges from one worksheet to another blobb Microsoft Excel Programming 7 29th May 2008 05:57 PM
Copy worksheet ranges from One Workbook to another from halem2 Microsoft Excel Worksheet Functions 0 24th Mar 2006 01:42 PM
Copy Worksheet plus ranges Ray Batig Microsoft Excel Programming 2 16th Mar 2005 10:56 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:23 PM.