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!
|