Selecting a Row

B

bgnjoe

(Posted previously to microsoft.public.project.vba group. Thanks for
pointing me in the right direction Mike.)

As will be obvious in my post, I'm not an expert in VBA, but would like
to learn how to create macros - starting with ones that seem easy and
have a practical use for me. For my first macro, I thought I'd try
changing the color of a row based on a flag and created the following:

Sub ChangeColor()
Dim t As Task
For Each t In ActiveProject.Tasks
If t.EnterpriseFlag1 Then
SelectRow Row:=t, RowRelative:=False
Font Color:=pjRed
End If
Next t
End Sub


The practice schedule I'm using has 14 tasks. The 13th task has the
EnterpriseFlag1 set to "Yes". When I run this, it changes the color of
the row for Task 5 to Red. Obviously, the "t" Task variable is not
behaving as I thought it would because t=5 when the actual row = 13.
What am I doing wrong? BTW. Using MS Project Pro 2003 and Enterprise
Server 2003.


As a side question, I downloaded the Proj98VBE training that I found
recommended in another post here (or maybe the server group). It's
fairly helpful, but I was wondering if anyone could recommend a book
that would help a beginner?


Thanks.
Joe
 
R

Rod Gill

Do you have a filter applied? If so, the visible row numbers and the row id
numbers will differ. It is safer to use T.ID in your code. Whilst the ID is
the default value for t, it is safer and clearer to always specify the
property you want (in this case the ID).
 
D

Dave

Thanks Rod. I did not have a filter applied, but Used T.ID and it
worked. Not sure I understand why, but I'll figure that out later.
 

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