Filtering on import to excel

J

Jeff

I want to selectively omit certain records during import using the
following code. How should I do it? What syntax is required.

Thanks
Jeff

'Copy Data
Set xlR = xlR.Offset(1, 0)
For Each Proj In Projects
'Use Subject field if it's not empty, otherwise the Title
field
If Proj.BuiltinDocumentProperties("Subject") = "" Then
ProjectName = Proj.BuiltinDocumentProperties("Subject")
Else
ProjectName = Proj.BuiltinDocumentProperties("Title")
End If
For Each R In Proj.Resources
For Each A In R.Assignments
xlR.Range("A1:E1") = Array(A.ResourceName,
A.TaskName, ProjectName, A.Work / 60, A.Cost)

'Export Time Phased Data
Set Tsvs = A.TimeScaleData(DateSerial(Year(Date),
Month(Date), 1), DateSerial(Year(Date), Month(Date) + 12, 1 - 1),
pjAssignmentTimescaledWork, pjTimescaleMonths)
For Each Tsv In Tsvs
If Tsv.Value <> "" Then 'If there is a
value to export
i = Month(Tsv.StartDate) -
Month(Date)
If i < 0 Then
i = i + 12
End If
xlR.Offset(0, i + 5) = Tsv.Value /
60
End If
Next
Set xlR = xlR.Offset(1, 0)
'point to next row in Excel
Next
Next
Next
 
J

JackD

Since we don't know which records you are going to filter out or how you
determine what they are, this is somewhat generic, but it gives the basic
idea:

for each task in activeproject.tasks
if <whatever criteria you are going to filter on> then
'do stuff
end if
next task

So it will only export things which match your criteria.

If you only wanted to export tasks named foo it would look like this:

for each task in activeproject.tasks
if task.name = "foo" then
'do stuff
end if
next task

You can add an else clause if you want to do something with the items that
do not meet your criteria.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top