Answered by:
Copying Specific Rows in a Project Plan to a New Plan

Question
-
Hi All
This should be a simple activity but for some reason I am struggling today. Basically I want to loop through all rows in a plan and where the field Text16 = "MOJ - Portal" I want to copy that activity to a new blank plan.
Any help/guidance would be appreciated. Once I have a solution for the name field for example I can do the rest. I am just struggling to get started.
Thanks in anticipation for any help/guidance on this.
Kind regards
Tony
TKHussar
Monday, May 23, 2016 11:30 AM
Answers
-
Hi Rod
That appears to do what I need. Many thanks for your help.
Apologies for the late response.
Kind regards
Tony
TKHussar
- Marked as answer by TKHussar Tuesday, June 19, 2018 10:46 AM
Saturday, May 28, 2016 9:53 AM
All replies
-
Hi TKHussar,
The bare bones would be something like... No doubt others will augment this...
Dim ts as Tasks
Dim t as Task
Set ts = ActiveProject.Tasks
For Each t in ts
If Not t is Nothing Then
If Not t.Summary Then
if t.text16 = "MOH - Portal" then'copy text16
' write it to the new file
end if
End If
End If
Next tMonday, May 23, 2016 12:44 PM -
Hi Ben
Many thanks for the quick response.
I want to include Summary Tasks but I can deal with that. Where I am struggling is how to write it to a blank plan.
Any help appreciated.
Kind regards
Tony
TKHussar
Monday, May 23, 2016 1:01 PM -
The copy method only works on the active selection AFAIK. So you need to make a filter that identifies all of the "MOH - -Portal" activities and then iterate through using the SelectRow method, copying and pasting as you go with the EditCopy ad EditPaste methods. You can select from one to all rows in the active selection. I've found that selecting one row at a time is slow but taking the entire set takes forever. I think you can only copy and paste with the active project. What I do is set two references, one for the source project and one for the destination project. As part of your "copy text 16" routine, you need to activate the source project when copying and the destination project when pasting.
Of course, if this is a one time thing, you could just make the filter, apply it, and highlight and copy/paste the activities by hand.
Monday, May 23, 2016 1:04 PM -
Hi Bill
Many thanks. This may be a weekly activity so Ideally I want to use VBA.
Thanks again.
Tony
TKHussar
Monday, May 23, 2016 1:18 PM -
How close is the following to what you want?
Sub CopyTasks() Dim prjOld As Project Dim prjNew As Project Dim TskNew As Task Dim TskOld As Task Set prjOld = ActiveProject Set prjNew = Projects.Add For Each TskOld In prjOld.Tasks If Not TskOld Is Nothing Then If TskOld.Text16 = "MOH - Portal" Then Set TskNew = prjNew.Tasks.Add(TskOld.Name) TskNew.Duration = TskOld.Duration TskNew.Text16 = TskOld.Text16 'Add extra fields as needed End If End If Next TskOld End Sub
Rod Gill
Author of the one and only Project VBA Book
www.project-systems.co.nz- Proposed as answer by John - Project Saturday, May 28, 2016 4:32 PM
Monday, May 23, 2016 8:37 PM -
Hi Rod
That appears to do what I need. Many thanks for your help.
Apologies for the late response.
Kind regards
Tony
TKHussar
- Marked as answer by TKHussar Tuesday, June 19, 2018 10:46 AM
Saturday, May 28, 2016 9:53 AM