Try to modify a row, but found out Task ID and row number are not

S

sxinkang

Dear All,
I am new to project VBA. I am working with project 2000 and trying to do
conditional formatting according to Values of Finish column. However, when it
points to one row's Finish value, it changes the color of another row. Main
code is as below.
************************************************
Dim tskT As Task
Dim diff As Integer

For Each tskT In ActiveProject.Tasks
SelectRow Row:=tskT.ID, rowrelative:=False
diff = DateValue(tskT.Finish) - DateValue(Date)
Select Case diff
Case Is > 0
Font Color:=pjRed
Case Is = 0
Font Color:=pjBlue
Case Is < 0
Font Color:=pjGreen
End Select
Next tskT

********************************************
Any advice or suggestion will be really appreciated!
 
J

Jan De Messemaeker

Hi,

There are two approaches here.
Either you add before your loop:
Outlineshowalltasks
filterapply "All Tasks"
Sort key1:="ID"
activeproject.displayprojectsummarytask=false
activeproject.ShowExternalPredecessors=false
activeproject.ShowExternalSuccessors=false


(These are six reaons why ID could be different from row number)

Or
SelectAll
set sel=activeselection.tasks
lines=sel.count
for counter=1 to lines
Set Job=activeselection.tasks(counter)
....

Next counter


Hope this helps,
--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
S

sxinkang

Dear Jan,
Thanks for quick reply.
I have tried your first approach.
It seems working, but there is some issue. The original file shows 800
lines. After the script, it shows 1373 lines. Is there anyway we can still
showing 800 lines?
(I guess the file was used some kind of filter or something.)

I will try the second approach and tell you if it works. Thank you so much.
 
J

Jan De Messemaeker

Hi,

Some kind of filter, yes, that is exactly why rows were not equal to ID's!
Normally the filter applied is visible (in the little filter window), or you
ccan read the name in Project menu, Filtered for...; if you note its name,
you can re-apply it after the macro.
To automate it start the macro with
FilterName=activeproject.currentfilter
and you end it with
Filterapply FilterName

HTH

--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
S

sxinkang

Dear Jan,
I define "Dim FilterName as String" and watch the value.

After
FilterName=activeproject.currentfilter

The FilterName is "AllTasks". Did I do something wrong? There is some filter
on "% Complete" and "Project Name" columns.
 
J

Jan De Messemaeker

Hi,

A-Ha!
It's not the filter, it's the fact that certain summary tasks are rolled
up... which is much harder to memorize I'm afraid..
Sorry, but i do not have the time to write this coding here and now.
HTH


--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 
S

sxinkang

Thanks for reply.
--
Walt


Jan De Messemaeker said:
Hi,

A-Ha!
It's not the filter, it's the fact that certain summary tasks are rolled
up... which is much harder to memorize I'm afraid..
Sorry, but i do not have the time to write this coding here and now.
HTH


--
Jan De Messemaeker
Microsoft Project Most Valuable Professional
+32 495 300 620
For availability check:
http://users.online.be/prom-ade/Calendar.pdf
 

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

Top