Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Copying a variable range of data from one worksheet to another.

I have a workbook with two worksheets. The first contains a listing of
activities and deliverables that comprise everything in a delivery process.
Not all are applicable to each process, so I use an indicator of "y/n" in
column C to indicate if that task will be completed. If column C is "Y", I
want to copy the contents of column D to the next worksheet. If it's "N", I
want to skip to the next row and check column C again. And so on, until the
end of my data range (which is set, so at least I know I only have to parse
rows 32 to 123).

Any help is much appreciated. If anything above is not clear I'll be happy
to clarify.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 33
Default Copying a variable range of data from one worksheet to another.

To solve this problem, I wrote some code. You can go into <Alt-<F11,
insert a module, and then paste this code into it.

I assumed that your two sheets were named "All Deliverables" where you keep
the entire list and the Y/N flag in column D and the deliverable name in
column C. I assumed the sheet you wanted to copy the "Y" deliverables to is
called "Deliverables to Complete". You can certainly change the names of the
sheets in the code to meet your needs. Further, I assumed that the column
header in the "Deliverables to Complete" sheet is in C1 and you want all of
the appropriate deliverables copied down from C2:C???.

This should work regardless of how many rows of deliverables you have (up to
5,000)

Sub CopyDeliverables()
Dim rngCopyFrom As Range
Dim rngCopyTo As Range

Sheets("Deliverables to Complete").Select
Set rngCopyTo = Range("C2")

Sheets("All Deliverables").Select

Range("C2").Select
For Each rngCopyFrom In Range("C2:C" & Range("C5000").End(xlUp).Row)
If UCase(rngCopyFrom.Offset(0, 1)) = "Y" Then
rngCopyTo = rngCopyFrom
Set rngCopyTo = rngCopyTo.Offset(1, 0)
End If
Next

End Sub


Let me know how it works!

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3
Default Copying a variable range of data from one worksheet to another

Thank you so much! This worked perfectly (okay, had to adjust for sheet
names, and locations but the main logic from you was perfect!)

You've saved me countless hours (not to mention countless aggravation!).

Alison

"GSnyder" wrote:

To solve this problem, I wrote some code. You can go into <Alt-<F11,
insert a module, and then paste this code into it.

I assumed that your two sheets were named "All Deliverables" where you keep
the entire list and the Y/N flag in column D and the deliverable name in
column C. I assumed the sheet you wanted to copy the "Y" deliverables to is
called "Deliverables to Complete". You can certainly change the names of the
sheets in the code to meet your needs. Further, I assumed that the column
header in the "Deliverables to Complete" sheet is in C1 and you want all of
the appropriate deliverables copied down from C2:C???.

This should work regardless of how many rows of deliverables you have (up to
5,000)

Sub CopyDeliverables()
Dim rngCopyFrom As Range
Dim rngCopyTo As Range

Sheets("Deliverables to Complete").Select
Set rngCopyTo = Range("C2")

Sheets("All Deliverables").Select

Range("C2").Select
For Each rngCopyFrom In Range("C2:C" & Range("C5000").End(xlUp).Row)
If UCase(rngCopyFrom.Offset(0, 1)) = "Y" Then
rngCopyTo = rngCopyFrom
Set rngCopyTo = rngCopyTo.Offset(1, 0)
End If
Next

End Sub


Let me know how it works!

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 33
Default Copying a variable range of data from one worksheet to another

My pleasure! If you get a chance, could you click the Yes at the bottom of
the post? That will mark the problem as answered.

Thanks and have a great day!
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
Variable named range in worksheet function Barb Reinhardt Excel Worksheet Functions 6 July 26th 08 03:39 AM
Copying A Range of Cells to Another Worksheet Rodman Excel Discussion (Misc queries) 4 May 6th 08 09:53 PM
universal copying over worksheet range pat in chard Excel Discussion (Misc queries) 1 April 23rd 08 12:51 PM
defining a variable-size worksheet area for copying & pasting z.entropic Excel Worksheet Functions 3 August 11th 07 09:30 PM
Looking up a variable in one worksheet and copying information from another column to another worksheet?? Brad Torken Excel Discussion (Misc queries) 2 December 10th 06 06:02 AM


All times are GMT +1. The time now is 03:04 AM.

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"