Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA that changes Font Color

Status
Not open for further replies.

DaveMac

Technical User
Apr 9, 2000
161
US
Need some help with a conditional format. I have two fields I would like to evaluate. I have a Due Data and a % Complete. I would like to have an If Due Date > Date() and % Complete <100 Font = Red type thing. I am starting with this piece of code I pulled from a site however the % Complete does not work because of the % character. I tried to [%Complete] but that did not work either.

So my question #1 Is how do I indicate the % Complete field in my code?

#2 Is how do I add the If Statements after this? I am thinking I want this to run then come back and run the ifs on the Due date stuff?????



Sub SelectTaskRows()
Dim tskT As Task

For Each tskT In ActiveProject.Tasks
Select Case tskT.% Complete
Case 1 To 50
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjYellow
Case 51 To 90
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjBlue
Case Is < 1
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjred
Case Is > 90
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjGreen
End Select
Next tskT

End Sub


Thanks for any help!
 
1. PercentComplete

2. Assuming that you want to ignore all tasks where DueDate is less than or equal to today:

before the Select line insert:

If TskT.TheNameOfTheFieldHoldingDueDataIs > Now() Then

after the End Select line insert:

Else
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjBlack
End if
 
Sorry but I have been trying my best to figure this one out but I cannot. I tried what was listed but I am just not getting it. The good news if I have a better approach. What I have now is Text24 is a formula that calculates properly and lists tasks as “Late”, “OK”, “Push”, “Due”, and “Done”. When I then add the below code it formats about 4 tasks then says The Argument Value is not valid. I have checked the values and there is no real reason I can see as to why this error kills the code? Any idea???



Sub SelectTaskRows()

Dim tskT As Task

For Each tskT In ActiveProject.Tasks

Select Case tskT.Text24
Case Is = "Late"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjRed
Case Is = "Due"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjgrey
Case Is = "Done"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjGreen
Case Is = "OK"
SelectRow Row:=tskT.ID, RowRelative:=False
Font Color:=pjBlack
End Select

Next tskT

End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top