Filter Loop

M

MarkC

Hi I am new to MSP VBA. I'm used to MS Excel version. I've had a look at a
few examples but can't see anything that's similar to mine.

What I am trying to do is go down my task list and change the text colours
depending on the project's status, say Flag1. I am trying to do more than but
for this example I will simplify things.

I've managed to create the folowing code but this does everything.

Dim T As Task
Dim Ts As Tasks

Set Ts = ActiveProject.Tasks
'SelectRow Row:=1
SelectRange Row:=1, Column:=2, RowRelative:=False
For Each T In Ts
SelectRow Row:=Row + 1
Font Color:=2
Next T

When I introduce the filter, say If Flag1="1", Flag1="2", etc, this does
nothing.

Can someone help. I am using MSP 2003 Standard.
 
M

MarkC

Thanks - That helped lots. It actually did what I wanted but ended with a
"runtime error 424 - Object Required.

Here's the sample code:
Dim T As Task
Dim Ts As Tasks

Set Ts = ActiveProject.Tasks
'SelectRow Row:=1
SelectRange Row:=1, Column:=2, RowRelative:=False
For Each T In Ts
SelectRow Row:=Row + 1
If ActiveSelection.Tasks(1).Text18 = "1" Then
Font Color:=2
End If
If ActiveSelection.Tasks(1).Text18 = "2" Then
Font Color:=3
End If
If ActiveSelection.Tasks(1).Text18 = "3" Then
Font Color:=4
End If
Next T
 
J

Jan De Messemaeker

One thing that may cause this is that you select a blank task
In that xcase activeselection. tasks(1) yields a Nothing object
Why do people always have blank tasks in a task list?

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

MarkC

Sorry I have been away.

This didnt work for me. On running a "compile error: sub or function not
defined." On the first "FontEx". On pressing help the error no is "35".

However I then noticed that this worked if I took out the "Ex" out.

Is there an explanation on what row and column references I should be using
and how to change these once I have created my macro.

Many thanks,

Mark
 
M

MarkC

Hi Jan,

Thanks for your reply. I have been away. Jack has come up with another
solution.

In terms of this method, if falls over after the last record, ie a blank
one, at this point of the code:

If ActiveSelection.Tasks(1).Text18 = "1" Then

I hope this helps. To me its implying there are more records which there
aren't.

Cheers,

Mark
 
M

MarkC

Oh yes there is a big problem with this solution - it only does the one
column (name) and not the whole row.
 

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